Added support for auto-backup path.

Ylian Saint-Hilaire committed May 22, 2019 at 15:22 UTC c9adc4d6e60d17c328ce859265030ec195f51678
3 files changed +11 -7
db.js
+8 -5
@@ -679,25 +679,28 @@ module.exports.CreateDB = function (parent, func) {
679 if (obj.performingBackup) return 1;
680 obj.performingBackup = true;
681 //console.log('Performing backup...');
682 - try { obj.parent.fs.mkdirSync(obj.parent.backuppath); } catch (e) { }
682 +
683 + var backupPath = obj.parent.backuppath;
684 + if (obj.parent.config.settings.autobackup && obj.parent.config.settings.autobackup.backuppath) { backupPath = obj.parent.config.settings.autobackup.backuppath; }
685 + try { obj.parent.fs.mkdirSync(backupPath); } catch (e) { }
686 const dbname = (obj.parent.args.mongodbname) ? (obj.parent.args.mongodbname) : 'meshcentral';
687 const currentDate = new Date();
688 const fileSuffix = currentDate.getFullYear() + '-' + padNumber(currentDate.getMonth() + 1, 2) + '-' + padNumber(currentDate.getDate(), 2) + '-' + padNumber(currentDate.getHours(), 2) + '-' + padNumber(currentDate.getMinutes(), 2);
689 const newAutoBackupFile = 'meshcentral-autobackup-' + fileSuffix;
687 - const newAutoBackupPath = obj.parent.path.join(obj.parent.backuppath, newAutoBackupFile);
690 + const newAutoBackupPath = obj.parent.path.join(backupPath, newAutoBackupFile);
691
692 if ((obj.databaseType == 2) || (obj.databaseType == 3)) {
693 // Perform a MongoDump backup
694 const newBackupFile = 'mongodump-' + fileSuffix;
692 - const newBackupPath = obj.parent.path.join(obj.parent.backuppath, newBackupFile);
695 + var newBackupPath = obj.parent.path.join(backupPath, newBackupFile);
696 var mongoDumpPath = 'mongodump';
697 if (obj.parent.config.settings.autobackup && obj.parent.config.settings.autobackup.mongodumppath) { mongoDumpPath = obj.parent.config.settings.autobackup.mongodumppath; }
698 const child_process = require('child_process');
699 const cmd = mongoDumpPath + ' --db \"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"';
697 - var backupProcess = child_process.exec(cmd, { cwd: obj.parent.backuppath }, function (error, stdout, stderr) {
700 + var backupProcess = child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) {
701 try {
702 backupProcess = null;
700 - if ((error != null) && (error != '')) { console.log('ERROR: Unable to perform database backup.\r\n'); obj.performingBackup = false; return; }
703 + if ((error != null) && (error != '')) { console.log('ERROR: Unable to perform database backup: ' + error + '\r\n'); obj.performingBackup = false; return; }
704
705 // Perform archive compression
706 var archiver = require('archiver');
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.3.5-b",
3 + "version": "0.3.5-c",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
sample-config.json
+2 -1
@@ -40,7 +40,8 @@
40 "_AutoBackup": {
41 "backupInvervalHours": 24,
42 "keepLastDaysBackup": 10,
43 - "zippassword": "MyReallySecretPassword3"
43 + "zipPassword": "MyReallySecretPassword3",
44 + "_backupPath": "C:\\backups"
45 }
46 },
47 "_domains": {