diff --git a/db.js b/db.js index 0f87684f..cd22074d 100644 --- a/db.js +++ b/db.js @@ -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'); diff --git a/package.json b/package.json index 8db9d03f..c8d7ccd2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.5-b", + "version": "0.3.5-c", "keywords": [ "Remote Management", "Intel AMT", diff --git a/sample-config.json b/sample-config.json index 9e4c457a..58a27e66 100644 --- a/sample-config.json +++ b/sample-config.json @@ -40,7 +40,8 @@ "_AutoBackup": { "backupInvervalHours": 24, "keepLastDaysBackup": 10, - "zippassword": "MyReallySecretPassword3" + "zipPassword": "MyReallySecretPassword3", + "_backupPath": "C:\\backups" } }, "_domains": {