+6
-5
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user