Allow setting retentionSecs in backendConfig

Part of #310
This commit is contained in:
Girish Ramakrishnan
2017-04-22 21:46:53 -07:00
parent abe72442ae
commit 29ae2cf8ca
4 changed files with 22 additions and 5 deletions
+6 -5
View File
@@ -115,16 +115,17 @@ function cleanupBackups(callback) {
settings.getBackupConfig(function (error, backupConfig) {
if (error) return callback(error);
// nothing to do here
if (backupConfig.provider !== 'filesystem') return callback();
if (backupConfig.retentionSecs < 0) return callback();
backups.getPaged(1, 1000, function (error, result) {
if (error) return callback(error);
// sort with latest backups first in the array and slice 2
var toCleanup = result.sort(function (a, b) { return b.creationTime.getTime() - a.creationTime.getTime(); }).slice(2);
var now = new Date();
var toCleanup = result.filter(function (a) {
return (now - a.creationTime) > (backupConfig.retentionSecs * 1000);
});
debug('cleanupBackups: about to clean: ', toCleanup);
debug('cleanupBackups: about to clean: %j', toCleanup);
async.each(toCleanup, function (backup, callback) {
backups.removeBackup(backup.id, backup.dependsOn, function (error) {
+1
View File
@@ -191,6 +191,7 @@ 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 ('key' in req.body && typeof req.body.key !== 'string') return next(new HttpError(400, 'key must be a string'));
settings.setBackupConfig(req.body, function (error) {