Added support for auto-backup path.

This commit is contained in:
Ylian Saint-Hilaire 2019-05-22 15:22:10 -07:00
parent 51ca9088a8
commit 705be0f280
3 changed files with 11 additions and 7 deletions

13
db.js
View File

@ -679,25 +679,28 @@ module.exports.CreateDB = function (parent, func) {
if (obj.performingBackup) return 1;
obj.performingBackup = true;
//console.log('Performing backup...');
try { obj.parent.fs.mkdirSync(obj.parent.backuppath); } catch (e) { }
var backupPath = obj.parent.backuppath;
if (obj.parent.config.settings.autobackup && obj.parent.config.settings.autobackup.backuppath) { backupPath = obj.parent.config.settings.autobackup.backuppath; }
try { obj.parent.fs.mkdirSync(backupPath); } catch (e) { }
const dbname = (obj.parent.args.mongodbname) ? (obj.parent.args.mongodbname) : 'meshcentral';
const currentDate = new Date();
const fileSuffix = currentDate.getFullYear() + '-' + padNumber(currentDate.getMonth() + 1, 2) + '-' + padNumber(currentDate.getDate(), 2) + '-' + padNumber(currentDate.getHours(), 2) + '-' + padNumber(currentDate.getMinutes(), 2);
const newAutoBackupFile = 'meshcentral-autobackup-' + fileSuffix;
const newAutoBackupPath = obj.parent.path.join(obj.parent.backuppath, newAutoBackupFile);
const newAutoBackupPath = obj.parent.path.join(backupPath, newAutoBackupFile);
if ((obj.databaseType == 2) || (obj.databaseType == 3)) {
// Perform a MongoDump backup
const newBackupFile = 'mongodump-' + fileSuffix;
const newBackupPath = obj.parent.path.join(obj.parent.backuppath, newBackupFile);
var newBackupPath = obj.parent.path.join(backupPath, newBackupFile);
var mongoDumpPath = 'mongodump';
if (obj.parent.config.settings.autobackup && obj.parent.config.settings.autobackup.mongodumppath) { mongoDumpPath = obj.parent.config.settings.autobackup.mongodumppath; }
const child_process = require('child_process');
const cmd = mongoDumpPath + ' --db \"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"';
var backupProcess = child_process.exec(cmd, { cwd: obj.parent.backuppath }, function (error, stdout, stderr) {
var backupProcess = child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) {
try {
backupProcess = null;
if ((error != null) && (error != '')) { console.log('ERROR: Unable to perform database backup.\r\n'); obj.performingBackup = false; return; }
if ((error != null) && (error != '')) { console.log('ERROR: Unable to perform database backup: ' + error + '\r\n'); obj.performingBackup = false; return; }
// Perform archive compression
var archiver = require('archiver');

View File

@ -1,6 +1,6 @@
{
"name": "meshcentral",
"version": "0.3.5-b",
"version": "0.3.5-c",
"keywords": [
"Remote Management",
"Intel AMT",

View File

@ -40,7 +40,8 @@
"_AutoBackup": {
"backupInvervalHours": 24,
"keepLastDaysBackup": 10,
"zippassword": "MyReallySecretPassword3"
"zipPassword": "MyReallySecretPassword3",
"_backupPath": "C:\\backups"
}
},
"_domains": {