autobackup improvements #6324

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Aug 15, 2024 at 11:32 UTC aae551dab9e9fe2b052a8a7bb9baaa6f265c3456
2 files changed +36 -15
db.js
+33 -13
@@ -3092,24 +3092,30 @@ module.exports.CreateDB = function (parent, func) {
3092 r += 'No Settings/AutoBackup\r\n';
3093 } else {
3094 if (parent.config.settings.autobackup.backupintervalhours != null) {
3095 + r += 'Backup Interval (Hours): ';
3096 if (typeof parent.config.settings.autobackup.backupintervalhours != 'number') { r += 'Bad backupintervalhours type\r\n'; }
3096 - else { r += 'Backup Interval (Hours): ' + parent.config.settings.autobackup.backupintervalhours + '\r\n'; }
3097 + else { r += parent.config.settings.autobackup.backupintervalhours + '\r\n'; }
3098 }
3099 if (parent.config.settings.autobackup.keeplastdaysbackup != null) {
3100 + r += 'Keep Last Backups (Days): ';
3101 if (typeof parent.config.settings.autobackup.keeplastdaysbackup != 'number') { r += 'Bad keeplastdaysbackup type\r\n'; }
3100 - else { r += 'Keep Last Backups (Days): ' + parent.config.settings.autobackup.keeplastdaysbackup + '\r\n'; }
3102 + else { r += parent.config.settings.autobackup.keeplastdaysbackup + '\r\n'; }
3103 }
3104 if (parent.config.settings.autobackup.zippassword != null) {
3103 - if (typeof parent.config.settings.autobackup.zippassword != 'string') { r += 'Bad zippassword type\r\n'; }
3104 - else { r += 'ZIP Password Set\r\n'; }
3105 + r += 'ZIP Password: ';
3106 + if (typeof parent.config.settings.autobackup.zippassword != 'string') { r += 'Bad zippassword type, Backups will not be encrypted\r\n'; }
3107 + else if (parent.config.settings.autobackup.zippassword == "") { r += 'Blank, Backups will not be encrypted\r\n'; }
3108 + else { r += 'Set\r\n'; }
3109 }
3110 if (parent.config.settings.autobackup.mongodumppath != null) {
3111 + r += 'MongoDump Path: ';
3112 if (typeof parent.config.settings.autobackup.mongodumppath != 'string') { r += 'Bad mongodumppath type\r\n'; }
3108 - else { r += 'MongoDump Path: ' + parent.config.settings.autobackup.mongodumppath + '\r\n'; }
3113 + else { r += parent.config.settings.autobackup.mongodumppath + '\r\n'; }
3114 }
3115 if (parent.config.settings.autobackup.mysqldumppath != null) {
3116 + r += 'MySqlDump Path: ';
3117 if (typeof parent.config.settings.autobackup.mysqldumppath != 'string') { r += 'Bad mysqldump type\r\n'; }
3112 - else { r += 'MySqlDump Path: ' + parent.config.settings.autobackup.mysqldumppath + '\r\n'; }
3118 + else { r += parent.config.settings.autobackup.mysqldumppath + '\r\n'; }
3119 }
3120 }
3121
@@ -3376,8 +3382,14 @@ module.exports.CreateDB = function (parent, func) {
3382 var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
3383 var archive = null;
3384 if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
3379 - try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { }
3380 - archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
3385 + try {
3386 + archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted'));
3387 + archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
3388 + if (func) { func('Creating encrypted ZIP'); }
3389 + } catch (ex) { // registering encryption failed, so create without encryption
3390 + archive = archiver('zip', { zlib: { level: 9 } });
3391 + if (func) { func('Creating encrypted ZIP failed, so falling back to normal ZIP'); }
3392 + }
3393 } else {
3394 archive = archiver('zip', { zlib: { level: 9 } });
3395 }
@@ -3414,11 +3426,13 @@ module.exports.CreateDB = function (parent, func) {
3426 var archiver = require('archiver');
3427 var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
3428 var archive = null;
3417 - if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
3418 - try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { }
3429 + try {
3430 + archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted'));
3431 archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
3420 - } else {
3432 + if (func) { func('Creating encrypted ZIP'); }
3433 + } catch (ex) { // registering encryption failed, so create without encryption
3434 archive = archiver('zip', { zlib: { level: 9 } });
3435 + if (func) { func('Creating encrypted ZIP failed, so falling back to normal ZIP'); }
3436 }
3437 output.on('close', function () {
3438 obj.performingBackup = false;
@@ -3442,8 +3456,14 @@ module.exports.CreateDB = function (parent, func) {
3456 var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
3457 var archive = null;
3458 if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
3445 - try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { }
3446 - archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
3459 + try {
3460 + archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted'));
3461 + archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
3462 + if (func) { func('Creating encrypted ZIP'); }
3463 + } catch (ex) { // registering encryption failed, so create without encryption
3464 + archive = archiver('zip', { zlib: { level: 9 } });
3465 + if (func) { func('Creating encrypted ZIP failed, so falling back to normal ZIP'); }
3466 + }
3467 } else {
3468 archive = archiver('zip', { zlib: { level: 9 } });
3469 }
meshcentral-config-schema.json
+3 -2
@@ -846,8 +846,9 @@
846 },
847 "zipPassword": {
848 "type": "string",
849 - "default": null,
850 - "description": "When specified, the ZIP backups will be password protected with the zipPassword"
849 + "default": "",
850 + "minLength": 1,
851 + "description": "When specified, the ZIP backups will be password protected with the zipPassword and the password cannot be a blank value"
852 },
853 "backupPath": {
854 "type": "string",