From aae551dab9e9fe2b052a8a7bb9baaa6f265c3456 Mon Sep 17 00:00:00 2001 From: si458 Date: Thu, 15 Aug 2024 11:32:24 +0100 Subject: [PATCH] autobackup improvements #6324 Signed-off-by: si458 --- db.js | 46 ++++++++++++++++++++++++---------- meshcentral-config-schema.json | 5 ++-- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/db.js b/db.js index c622d83b..b183193b 100644 --- a/db.js +++ b/db.js @@ -3092,24 +3092,30 @@ module.exports.CreateDB = function (parent, func) { r += 'No Settings/AutoBackup\r\n'; } else { if (parent.config.settings.autobackup.backupintervalhours != null) { + r += 'Backup Interval (Hours): '; if (typeof parent.config.settings.autobackup.backupintervalhours != 'number') { r += 'Bad backupintervalhours type\r\n'; } - else { r += 'Backup Interval (Hours): ' + parent.config.settings.autobackup.backupintervalhours + '\r\n'; } + else { r += parent.config.settings.autobackup.backupintervalhours + '\r\n'; } } if (parent.config.settings.autobackup.keeplastdaysbackup != null) { + r += 'Keep Last Backups (Days): '; if (typeof parent.config.settings.autobackup.keeplastdaysbackup != 'number') { r += 'Bad keeplastdaysbackup type\r\n'; } - else { r += 'Keep Last Backups (Days): ' + parent.config.settings.autobackup.keeplastdaysbackup + '\r\n'; } + else { r += parent.config.settings.autobackup.keeplastdaysbackup + '\r\n'; } } if (parent.config.settings.autobackup.zippassword != null) { - if (typeof parent.config.settings.autobackup.zippassword != 'string') { r += 'Bad zippassword type\r\n'; } - else { r += 'ZIP Password Set\r\n'; } + r += 'ZIP Password: '; + if (typeof parent.config.settings.autobackup.zippassword != 'string') { r += 'Bad zippassword type, Backups will not be encrypted\r\n'; } + else if (parent.config.settings.autobackup.zippassword == "") { r += 'Blank, Backups will not be encrypted\r\n'; } + else { r += 'Set\r\n'; } } if (parent.config.settings.autobackup.mongodumppath != null) { + r += 'MongoDump Path: '; if (typeof parent.config.settings.autobackup.mongodumppath != 'string') { r += 'Bad mongodumppath type\r\n'; } - else { r += 'MongoDump Path: ' + parent.config.settings.autobackup.mongodumppath + '\r\n'; } + else { r += parent.config.settings.autobackup.mongodumppath + '\r\n'; } } if (parent.config.settings.autobackup.mysqldumppath != null) { + r += 'MySqlDump Path: '; if (typeof parent.config.settings.autobackup.mysqldumppath != 'string') { r += 'Bad mysqldump type\r\n'; } - else { r += 'MySqlDump Path: ' + parent.config.settings.autobackup.mysqldumppath + '\r\n'; } + else { r += parent.config.settings.autobackup.mysqldumppath + '\r\n'; } } } @@ -3376,8 +3382,14 @@ module.exports.CreateDB = function (parent, func) { var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip'); var archive = null; if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) { - try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { } - archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword }); + try { + archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); + archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword }); + if (func) { func('Creating encrypted ZIP'); } + } catch (ex) { // registering encryption failed, so create without encryption + archive = archiver('zip', { zlib: { level: 9 } }); + if (func) { func('Creating encrypted ZIP failed, so falling back to normal ZIP'); } + } } else { archive = archiver('zip', { zlib: { level: 9 } }); } @@ -3414,11 +3426,13 @@ module.exports.CreateDB = function (parent, func) { var archiver = require('archiver'); var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip'); var archive = null; - if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) { - try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { } + try { + archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword }); - } else { + if (func) { func('Creating encrypted ZIP'); } + } catch (ex) { // registering encryption failed, so create without encryption archive = archiver('zip', { zlib: { level: 9 } }); + if (func) { func('Creating encrypted ZIP failed, so falling back to normal ZIP'); } } output.on('close', function () { obj.performingBackup = false; @@ -3442,8 +3456,14 @@ module.exports.CreateDB = function (parent, func) { var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip'); var archive = null; if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) { - try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { } - archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword }); + try { + archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); + archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword }); + if (func) { func('Creating encrypted ZIP'); } + } catch (ex) { // registering encryption failed, so create without encryption + archive = archiver('zip', { zlib: { level: 9 } }); + if (func) { func('Creating encrypted ZIP failed, so falling back to normal ZIP'); } + } } else { archive = archiver('zip', { zlib: { level: 9 } }); } diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index 035dae66..76c53345 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -846,8 +846,9 @@ }, "zipPassword": { "type": "string", - "default": null, - "description": "When specified, the ZIP backups will be password protected with the zipPassword" + "default": "", + "minLength": 1, + "description": "When specified, the ZIP backups will be password protected with the zipPassword and the password cannot be a blank value" }, "backupPath": { "type": "string",