Add mongodump args option (#6921)

* Add mongodump args option * Put mongodumpargs in proper place

PTR committed Apr 12, 2025 at 11:00 UTC c202339b67cb579f942cd2d8fa50f586fff4468a
2 files changed +9 -2
db.js
+5 -2
@@ -3323,7 +3323,10 @@ module.exports.CreateDB = function (parent, func) {
3323
3324 var cmd = '"' + mongoDumpPath + '"';
3325 if (dburl) { cmd = '\"' + mongoDumpPath + '\" --uri=\"' + dburl + '\"'; }
3326 -
3326 + if (parent.config.settings.autobackup?.mongodumpargs) {
3327 + cmd = '\"' + mongoDumpPath + '\" ' + parent.config.settings.autobackup.mongodumpargs;
3328 + if (!parent.config.settings.autobackup.mongodumpargs.includes("--db=")) {cmd += ' --db=' + (parent.config.settings.mongodbname ? parent.config.settings.mongodbname : 'meshcentral')};
3329 + }
3330 return cmd;
3331 }
3332
@@ -3378,7 +3381,7 @@ module.exports.CreateDB = function (parent, func) {
3381 const child_process = require('child_process');
3382 child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) {
3383 if ((error != null) && (error != '')) {
3381 - func(1, "Unable to find mongodump tool, backup will not be performed. Command tried: " + cmd);
3384 + func(1, "Mongodump error, backup will not be performed. Command tried: " + cmd + ' --> ERROR: ' + stderr);
3385 return;
3386 } else {parent.config.settings.autobackup.backupintervalhours = backupInterval;}
3387 });
meshcentral-config-schema.json
+4
@@ -886,6 +886,10 @@
886 "default": "mongodump",
887 "description": "The file path of where \"mongodump\" is located. Default is \"mongodump\""
888 },
889 + "mongoDumpArgs": {
890 + "type": "string",
891 + "description": "Override the default mongodump --uri=<mongoDb>. The --db= option is automatically appended if omitted. (f.e. --host=127.0.0.1 --username=someUser --password=PaSsWORD --authenticationDatabase=admin)"
892 + },
893 "mysqlDumpPath": {
894 "type": "string",
895 "default": "mysqldump",