alse 4 years ago
parent f6a55ad592
commit 64b5f0f34d

@ -122,8 +122,10 @@ app.get(routes.crontab, function(req, res, next) {
// backup crontab db // backup crontab db
app.get(routes.backup, function(req, res) { app.get(routes.backup, function(req, res) {
crontab.backup(); crontab.backup((err) => {
res.end(); if (err) next(err);
else res.end();
});
}); });
// This renders the restore page similar to backup page // This renders the restore page similar to backup page

@ -220,27 +220,24 @@ exports.get_backup_names = function(){
} }
}); });
// Sort by date. Newest on top let backup_date = (backup_name) => {
for(var i=0; i<backups.length; i++){ let T = backup_name.split("backup")[1];
var Ti = backups[i].split("backup")[1]; return new Date(T.substring(0, T.length-3)).valueOf();
Ti = new Date(Ti.substring(0, Ti.length-3)).valueOf();
for(var j=0; j<i; j++){
var Tj = backups[j].split("backup")[1];
Tj = new Date(Tj.substring(0, Tj.length-3)).valueOf();
if(Ti > Tj){
var temp = backups[i];
backups[i] = backups[j];
backups[j] = temp;
}
}
} }
backups.sort((a, b) => backup_date(b) - backup_date(a));
return backups; return backups;
}; };
exports.backup = function(){ exports.backup = (callback) => {
//TODO check if it failed fs.copyFile(exports.crontab_db_file, path.join(exports.db_folder, 'backup ' + (new Date()).toString().replace("+", " ") + '.db'), (err) => {
fs.createReadStream(exports.crontab_db_file).pipe(fs.createWriteStream( path.join(exports.db_folder, 'backup ' + (new Date()).toString().replace("+", " ") + '.db'))); if (err) {
console.error(err);
return callback(err);
}
callback();
});
}; };
exports.restore = function(db_name){ exports.restore = function(db_name){

Loading…
Cancel
Save