Improved auto-backup, missing modules recovery.

Ylian Saint-Hilaire committed May 17, 2019 at 15:44 UTC c02fe3ca03ffba9b9da7d8306f59d39f92241ea4
4 files changed +36 -20
db.js
+9 -4
@@ -668,8 +668,11 @@ module.exports.CreateDB = function (parent, func) {
668 func(obj); // Completed function setup
669 }
670
671 + obj.performingBackup = false;
672 obj.performBackup = function () {
672 - console.log('Performing backup...');
673 + if (obj.performingBackup) return 1;
674 + obj.performingBackup = true;
675 + //console.log('Performing backup...');
676 try { obj.parent.fs.mkdirSync(obj.parent.backuppath); } catch (e) { }
677 const dbname = (obj.parent.args.mongodbname) ? (obj.parent.args.mongodbname) : 'meshcentral';
678 const currentDate = new Date();
@@ -687,7 +690,7 @@ module.exports.CreateDB = function (parent, func) {
690 const cmd = mongoDumpPath + ' --db \"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"';
691 var backupProcess = child_process.exec(cmd, { cwd: obj.parent.backuppath }, function (error, stdout, stderr) {
692 backupProcess = null;
690 - if ((error != null) && (error != '')) { console.log('ERROR: Unable to perform database backup.\r\n'); return; }
693 + if ((error != null) && (error != '')) { console.log('ERROR: Unable to perform database backup.\r\n'); obj.performingBackup = false; return; }
694
695 // Perform archive compression
696 var archiver = require('archiver');
@@ -699,7 +702,7 @@ module.exports.CreateDB = function (parent, func) {
702 } else {
703 archive = archiver('zip', { zlib: { level: 9 } });
704 }
702 - output.on('close', function () { setTimeout(function () { try { obj.parent.fs.unlink(newBackupPath + '.archive'); } catch (ex) { } }, 5000); });
705 + output.on('close', function () { obj.performingBackup = false; setTimeout(function () { try { obj.parent.fs.unlink(newBackupPath + '.archive'); } catch (ex) { console.log(ex); } }, 5000); });
706 output.on('end', function () { });
707 archive.on('warning', function (err) { console.log('Backup warning: ' + err); });
708 archive.on('error', function (err) { console.log('Backup error: ' + err); });
@@ -719,7 +722,7 @@ module.exports.CreateDB = function (parent, func) {
722 } else {
723 archive = archiver('zip', { zlib: { level: 9 } });
724 }
722 - output.on('close', function () { });
725 + output.on('close', function () { obj.performingBackup = false; });
726 output.on('end', function () { });
727 archive.on('warning', function (err) { console.log('Backup warning: ' + err); });
728 archive.on('error', function (err) { console.log('Backup error: ' + err); });
@@ -747,6 +750,8 @@ module.exports.CreateDB = function (parent, func) {
750 }
751 });
752 }
753 +
754 + return 0;
755 }
756
757 function padNumber(number, digits) { return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number; }
meshcentral.js
+5 -2
@@ -1707,12 +1707,15 @@ process.on('SIGINT', function () { if (meshserver != null) { meshserver.Stop();
1707 // Load the really basic modules
1708 var meshserver = null;
1709 var previouslyInstalledModules = { };
1710 -function mainStart(args) {
1710 +function mainStart() {
1711 // Check the NodeJS is version 6 or better.
1712 if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 6) { console.log("MeshCentral requires Node v6.x or above, current version is " + process.version + "."); return; }
1713
1714 // Check for any missing modules.
1715 InstallModules(['minimist'], function () {
1716 + // Parse inbound arguments
1717 + var args = require('minimist')(process.argv.slice(2));
1718 +
1719 // Get the server configuration
1720 var config = getConfig(false);
1721 if (config == null) { process.exit(); }
@@ -1764,7 +1767,7 @@ function mainStart(args) {
1767 }
1768
1769 if (require.main === module) {
1767 - mainStart(require('minimist')(process.argv.slice(2))); // Called directly, launch normally.
1770 + mainStart(); // Called directly, launch normally.
1771 } else {
1772 module.exports.mainStart = mainStart; // Required as a module, useful for winservice.js
1773 }
meshuser.js
+7 -1
@@ -524,7 +524,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
524 switch (cmd) {
525 case 'help': {
526 r = 'Available commands: help, info, versions, args, resetserver, showconfig, usersessions, tasklimiter, setmaxtasks, cores,\r\n'
527 - r += 'migrationagents, agentstats, webstats, mpsstats, swarmstats, acceleratorsstats, updatecheck, serverupdate, nodeconfig, heapdump, relays.';
527 + r += 'migrationagents, agentstats, webstats, mpsstats, swarmstats, acceleratorsstats, updatecheck, serverupdate, nodeconfig,\r\n';
528 + r += 'heapdump, relays, autobackup.';
529 break;
530 }
531 case 'agentstats': {
@@ -703,6 +704,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
704 if (r == '') { r = 'No relays.'; }
705 break;
706 }
707 + case 'autobackup': {
708 + var backupResult = parent.db.performBackup();
709 + if (backupResult == 0) { r = 'Starting auto-backup...'; } else { r = 'Backup alreay in progress.'; }
710 + break;
711 + }
712 default: { // This is an unknown command, return an error message
713 r = 'Unknown command \"' + cmd + '\", type \"help\" for list of avaialble commands.';
714 break;
views/default.handlebars
+15 -13
@@ -6051,19 +6051,21 @@
6051 x += addHtmlValue('Features', addLinkConditional(meshFeatures, 'p20editmeshfeatures()', meshrights & 1));
6052
6053 // Display user consent
6054 - meshFeatures = [];
6055 - var consent = 0;
6056 - if (currentMesh.consent) { consent = currentMesh.consent; }
6057 - if (serverinfo.consent) { consent |= serverinfo.consent; }
6058 - if (consent & 0x0008) { meshFeatures.push('Desktop Prompt'); } else { if (consent & 0x0001) { meshFeatures.push('Desktop Notify'); } }
6059 - if (consent & 0x0010) { meshFeatures.push('Terminal Prompt'); } else { if (consent & 0x0002) { meshFeatures.push('Terminal Notify'); } }
6060 - if (consent & 0x0020) { meshFeatures.push('Files Prompt'); } else { if (consent & 0x0004) { meshFeatures.push('Files Notify'); } }
6061 - //if ((consent & 7) == 7) { meshFeatures.push('Always Notify'); } else if ((currentMesh.consent & 7) != 0) { meshFeatures.push('Notify Sometimes'); }
6062 - //if ((consent & 56) == 56) { meshFeatures.push('Always Blink Border'); } else if ((currentMesh.consent & 56) != 0) { meshFeatures.push('Blick Border Sometimes'); }
6063 -
6064 - meshFeatures = meshFeatures.join(', ');
6065 - if (meshFeatures == '') { meshFeatures = '<i>None</i>'; }
6066 - x += addHtmlValue('User Consent', addLinkConditional(meshFeatures, 'p20editmeshconsent()', meshrights & 1));
6054 + if (currentMesh.mtype == 2) {
6055 + meshFeatures = [];
6056 + var consent = 0;
6057 + if (currentMesh.consent) { consent = currentMesh.consent; }
6058 + if (serverinfo.consent) { consent |= serverinfo.consent; }
6059 + if (consent & 0x0008) { meshFeatures.push('Desktop Prompt'); } else { if (consent & 0x0001) { meshFeatures.push('Desktop Notify'); } }
6060 + if (consent & 0x0010) { meshFeatures.push('Terminal Prompt'); } else { if (consent & 0x0002) { meshFeatures.push('Terminal Notify'); } }
6061 + if (consent & 0x0020) { meshFeatures.push('Files Prompt'); } else { if (consent & 0x0004) { meshFeatures.push('Files Notify'); } }
6062 + if (consent == 7) { meshFeatures = ['Always Notify']; }
6063 + if ((consent & 56) == 56) { meshFeatures = ['Always Prompt']; }
6064 +
6065 + meshFeatures = meshFeatures.join(', ');
6066 + if (meshFeatures == '') { meshFeatures = '<i>None</i>'; }
6067 + x += addHtmlValue('User Consent', addLinkConditional(meshFeatures, 'p20editmeshconsent()', meshrights & 1));
6068 + }
6069
6070 // Intel AMT setup
6071 if (currentMesh.mtype == 2) {