Commit d992702b authored by Girish Ramakrishnan's avatar Girish Ramakrishnan

rename to keepWithinSecs

part of #441
parent 6a9fe112
......@@ -5,7 +5,7 @@ exports.up = function(db, callback) {
if (error || results.length === 0) return callback(error);
var backupConfig = JSON.parse(results[0].value);
backupConfig.retentionPolicy = { keepWithin: backupConfig.retentionSecs };
backupConfig.retentionPolicy = { keepWithinSecs: backupConfig.retentionSecs };
delete backupConfig.retentionSecs;
// mark old encrypted backups as v1
......
......@@ -132,13 +132,16 @@ function testConfig(backupConfig, callback) {
if (backupConfig.format !== 'tgz' && backupConfig.format !== 'rsync') return callback(new BoxError(BoxError.BAD_FIELD, 'unknown format', { field: 'format' }));
// remember to adjust the cron ensureBackup task interval accordingly
if (backupConfig.intervalSecs < 6 * 60 * 60) return callback(new BoxError(BoxError.BAD_FIELD, 'Interval must be atleast 6 hours', { field: 'interval' }));
if (backupConfig.intervalSecs < 6 * 60 * 60) return callback(new BoxError(BoxError.BAD_FIELD, 'Interval must be atleast 6 hours', { field: 'intervalSecs' }));
if ('password' in backupConfig) {
if (typeof backupConfig.password !== 'string') return callback(new BoxError(BoxError.BAD_FIELD, 'password must be a string', { field: 'password' }));
if (backupConfig.password.length < 8) return callback(new BoxError(BoxError.BAD_FIELD, 'password must be atleast 8 characters', { field: 'password' }));
}
const policy = backupConfig.retentionPolicy;
if ('keepWithinSecs' in policy && typeof policy.keepWithinSecs !== 'number') return callback(new BoxError(BoxError.BAD_FIELD, 'keepWithinSecs must be a number', { field: 'retentionPolicy' }));
api(backupConfig.provider).testConfig(backupConfig, callback);
}
......@@ -1272,7 +1275,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.retentionPolicy.keepWithin * 1000)) return iteratorDone();
if ((now - appBackup.creationTime) < (backupConfig.retentionPolicy.keepWithinSecs * 1000)) return iteratorDone();
debug('cleanupAppBackups: removing %s', appBackup.id);
......@@ -1317,7 +1320,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.retentionPolicy.keepWithin * 1000)) {
if ((now - boxBackup.creationTime) < (backupConfig.retentionPolicy.keepWithinSecs * 1000)) {
referencedAppBackups = referencedAppBackups.concat(boxBackup.dependsOn);
return iteratorNext();
}
......@@ -1391,7 +1394,7 @@ function cleanup(auditSource, progressCallback, callback) {
settings.getBackupConfig(function (error, backupConfig) {
if (error) return callback(error);
if (backupConfig.retentionPolicy.keepWithin < 0) {
if (backupConfig.retentionPolicy.keepWithinSecs < 0) {
debug('cleanup: keeping all backups');
return callback(null, {});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment