One more fix for mongodump.exe invocation.
Ylian Saint-Hilaire committed
May 20, 2021 at 13:54 UTC
626364bab81fbac745ee9ec67d4f00631120744a
1 file changed
+8
-2
db.js
+8
-2
@@ -1644,6 +1644,12 @@ module.exports.CreateDB = function (parent, func) {
1644
return cmd;
1645
}
1646
1647
+ // MongoDB mongodump requires that the URL have a / at the end of the path. If not present, this will add it.
1648
+ function terminateUrlPathWithSlash(str) {
1649
+ const u = require('url').parse(str);
1650
+ return u.protocol + '//' + u.host + (u.pathname ? u.pathname : '') + '/' + (u.search ? u.search : '');
1651
+ }
1652
+
1653
// Check that the server is capable of performing a backup
1654
obj.checkBackupCapability = function (func) {
1655
if ((parent.config.settings.autobackup == null) || (parent.config.settings.autobackup == false)) { func(); }
@@ -1656,7 +1662,7 @@ module.exports.CreateDB = function (parent, func) {
1662
var mongoDumpPath = 'mongodump';
1663
if (parent.config.settings.autobackup && parent.config.settings.autobackup.mongodumppath) { mongoDumpPath = parent.config.settings.autobackup.mongodumppath; }
1664
var cmd = '"' + mongoDumpPath + '"';
1659
- if (dburl) { cmd = '\"' + mongoDumpPath + '\" --uri=\"' + dburl + '\"'; }
1665
+ if (dburl) { cmd = '\"' + mongoDumpPath + '\" --uri=\"' + terminateUrlPathWithSlash(dburl) + '\"'; }
1666
cmd += (parent.platform == 'win32') ? ' --archive=\"nul\"' : ' --archive=\"/dev/null\"';
1667
const child_process = require('child_process');
1668
child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) {
@@ -1834,7 +1840,7 @@ module.exports.CreateDB = function (parent, func) {
1840
if (parent.config.settings.autobackup && parent.config.settings.autobackup.mongodumppath) { mongoDumpPath = parent.config.settings.autobackup.mongodumppath; }
1841
const child_process = require('child_process');
1842
var cmd = '\"' + mongoDumpPath + '\" --db=\"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"';
1837
- if (dburl) { cmd = '\"' + mongoDumpPath + '\" --uri=\"' + dburl + '\" --archive=\"' + newBackupPath + '.archive\"'; }
1843
+ if (dburl) { cmd = '\"' + mongoDumpPath + '\" --uri=\"' + terminateUrlPathWithSlash(dburl) + '\" --archive=\"' + newBackupPath + '.archive\"'; }
1844
var backupProcess = child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) {
1845
try {
1846
var mongoDumpSuccess = true;