UNPKG

ernest

Version:

Web framework for HTTP and HTTPS, using ExpressJS, Session, Mongo, Socket IO, Redis

75 lines (69 loc) 1.43 kB
var fs = require('fs'); var Ernest_OS = require('./Ernest_OS'); var Ernest_Files = require('./Ernest_Files'); class Ernest_DB_BKP { constructor(dbname) { this.dbname = dbname; this.OS = new Ernest_OS(); this.files = new Ernest_Files(); }; Create_BackUp(dst_path,callback) { if( dst_path.charAt(dst_path.length -1) != "/") { dst_path = dst_path + "/"; }; var _this = this; this.OS.exec('mongodump --db ' + this.dbname ,function(err,stdo,stde) { if(err) { console.log(err); callback(false); } else { _this.files.Compress_Folder(__dirname + "/dump/",dst_path + _this.dbname+".tar.gz",function(e,r) { if(e) { callback(false); } else { _this.files.DeleteFolder(__dirname + "/dump/",function() { callback(true); }); }; }); }; }); }; Restore_BackUp(src_path,tarfile,new_dbname,callback) { var _this = this; _this.files.Decompress_Folder(src_path+ "/" + tarfile,src_path + "/dump/",function(r) { var comm = "mongorestore --db " + new_dbname + " " + src_path + "/dump/" + _this.dbname + "/"; _this.OS.exec(comm,function(err,stdo,stde) { if(err) { console.log(err); callback(false); } else { _this.files.DeleteFolder(src_path + "/dump/",function() { callback(true); }); }; }); }); }; }; module.exports = Ernest_DB_BKP;