move retentionSecs inside retentionPolicy

part of #441
This commit is contained in:
Girish Ramakrishnan
2020-05-14 16:19:35 -07:00
parent 573da29a4d
commit 6a9fe1128f
5 changed files with 27 additions and 7 deletions

View File

@@ -1272,7 +1272,7 @@ function cleanupAppBackups(backupConfig, referencedAppBackups, callback) {
async.eachSeries(appBackups, function iterator(appBackup, iteratorDone) {
if (referencedAppBackups.indexOf(appBackup.id) !== -1) return iteratorDone();
if ((now - appBackup.creationTime) < (appBackup.preserveSecs * 1000)) return iteratorDone();
if ((now - appBackup.creationTime) < (backupConfig.retentionSecs * 1000)) return iteratorDone();
if ((now - appBackup.creationTime) < (backupConfig.retentionPolicy.keepWithin * 1000)) return iteratorDone();
debug('cleanupAppBackups: removing %s', appBackup.id);
@@ -1317,7 +1317,7 @@ function cleanupBoxBackups(backupConfig, auditSource, callback) {
async.eachSeries(boxBackups, function iterator(boxBackup, iteratorNext) {
// TODO: errored backups should probably be cleaned up before retention time, but we will
// have to be careful not to remove any backup currently being created
if ((now - boxBackup.creationTime) < (backupConfig.retentionSecs * 1000)) {
if ((now - boxBackup.creationTime) < (backupConfig.retentionPolicy.keepWithin * 1000)) {
referencedAppBackups = referencedAppBackups.concat(boxBackup.dependsOn);
return iteratorNext();
}
@@ -1391,7 +1391,7 @@ function cleanup(auditSource, progressCallback, callback) {
settings.getBackupConfig(function (error, backupConfig) {
if (error) return callback(error);
if (backupConfig.retentionSecs < 0) {
if (backupConfig.retentionPolicy.keepWithin < 0) {
debug('cleanup: keeping all backups');
return callback(null, {});
}

View File

@@ -97,7 +97,6 @@ function setBackupConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
if (typeof req.body.retentionSecs !== 'number') return next(new HttpError(400, 'retentionSecs is required'));
if (typeof req.body.intervalSecs !== 'number') return next(new HttpError(400, 'intervalSecs is required'));
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password must be a string'));
if ('syncConcurrency' in req.body) {
@@ -107,6 +106,9 @@ function setBackupConfig(req, res, next) {
if (typeof req.body.format !== 'string') return next(new HttpError(400, 'format must be a string'));
if ('acceptSelfSignedCerts' in req.body && typeof req.body.acceptSelfSignedCerts !== 'boolean') return next(new HttpError(400, 'format must be a boolean'));
if (!req.body.retentionPolicy || typeof req.body.retentionPolicy !== 'object') return next(new HttpError(400, 'retentionPolicy is required'));
if (typeof req.body.retentionPolicy.keepWithin !== 'number') return next(400, 'keepWithin is required');
// testing the backup using put/del takes a bit of time at times
req.clearTimeout();

View File

@@ -145,7 +145,7 @@ let gDefaults = (function () {
backupFolder: '/var/backups',
format: 'tgz',
encryption: null,
retentionSecs: 2 * 24 * 60 * 60, // 2 days
retentionPolicy: { keepWithin: 2 * 24 * 60 * 60 }, // 2 days
intervalSecs: 24 * 60 * 60 // ~1 day
};
result[exports.PLATFORM_CONFIG_KEY] = {};
@@ -428,7 +428,7 @@ function setBackupCredentials(credentials, callback) {
if (error) return callback(error);
// preserve these fields
const extra = _.pick(currentConfig, 'retentionSecs', 'intervalSecs', 'copyConcurrency', 'syncConcurrency');
const extra = _.pick(currentConfig, 'retentionPolicy', 'intervalSecs', 'copyConcurrency', 'syncConcurrency');
const backupConfig = _.extend({}, credentials, extra);

View File

@@ -80,7 +80,7 @@ describe('backups', function () {
provider: 'filesystem',
password: 'supersecret',
backupFolder: BACKUP_DIR,
retentionSecs: 1,
retentionPolicy: { keepWithin: 1 },
format: 'tgz'
})
], done);