take backup

This commit is contained in:
Suresh Alse
2015-06-13 00:49:46 +05:30
parent b73c16c8c4
commit 9c48e80748
7 changed files with 117 additions and 18 deletions

View File

@@ -24,6 +24,14 @@ exports.create_new = function(name, command, schedule){
exports.update = function(data){
db.update({_id: data._id}, crontab(data.name, data.command, data.schedule, null));
}
exports.status = function(_id, stopped){
db.update({_id: _id},{$set: {stopped: stopped}});
}
exports.remove = function(_id){
db.remove({_id: _id}, {});
}
exports.crontabs = function(callback){
db.find({}, function(err, docs){
callback(docs);
@@ -43,3 +51,20 @@ exports.set_crontab = function(){
});
}
exports.get_backup_names = function(){
var backups = []
fs.readdirSync(__dirname + '/crontabs').forEach(function(file){
// file name begins with backup
if(file.indexOf("backup") == 0){
backups.push(file);
}
});
return backups;
}
exports.backup = function(){
//TODO check if it failed
fs.createReadStream( __dirname + '/crontabs/crontab.db').pipe(fs.createWriteStream( __dirname + '/crontabs/backup ' + (new Date()).toString() + '.db'));
}