|
|
@ -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){
|
|
|
|