Add cron job stub for backup cleaning in janitor

This commit is contained in:
Johannes Zellner
2016-10-05 17:19:53 +02:00
parent 882ed72f14
commit e2c206b755
2 changed files with 39 additions and 1 deletions

View File

@@ -3,13 +3,16 @@
var assert = require('assert'),
async = require('async'),
authcodedb = require('./authcodedb.js'),
backups = require('./backups.js'),
debug = require('debug')('box:src/janitor'),
docker = require('./docker.js').connection,
settings = require('./settings.js'),
tokendb = require('./tokendb.js');
exports = module.exports = {
cleanupTokens: cleanupTokens,
cleanupDockerVolumes: cleanupDockerVolumes
cleanupDockerVolumes: cleanupDockerVolumes,
cleanupBackups: cleanupBackups
};
var NOOP_CALLBACK = function () { };
@@ -101,3 +104,26 @@ function cleanupDockerVolumes(callback) {
}, callback);
});
}
function cleanupBackups(callback) {
assert(!callback || typeof callback === 'function'); // callback is null when called from cronjob
callback = callback || NOOP_CALLBACK;
debug('Cleaning backups');
settings.getBackupConfig(function (error, backupConfig) {
if (error) return callback(error);
// nothing to do here
if (backupConfig.provider !== 'filesystem') return callback();
backups.getPaged(1, 1000, function (error, result) {
if (error) return callback(error);
debug('Current backups:', result);
callback();
});
});
}