Added MariaDB/MySQL to checkBackupCapability
Noah Zalev committed
Apr 10, 2021 at 17:21 UTC
34aa47a81330764b3fa9aec16b55e5e3e5f14716
1 file changed
+26
db.js
+26
@@ -1610,6 +1610,32 @@ module.exports.CreateDB = function (parent, func) {
1610
}
1611
} catch (ex) { console.log(ex); }
1612
});
1613
+ } else if ((obj.databaseType == 4) || (obj.databaseType == 5)) {
1614
+ // Check that we have access to mysqldump
1615
+ var backupPath = parent.backuppath;
1616
+ if (parent.config.settings.autobackup && parent.config.settings.autobackup.backuppath) { backupPath = parent.config.settings.autobackup.backuppath; }
1617
+ try { parent.fs.mkdirSync(backupPath); } catch (e) { }
1618
+ var props = (obj.databaseType == 4) ? parent.args.mariadb : parent.args.mysql;
1619
+ var mysqldumpPath = 'mysqldump';
1620
+ if (parent.config.settings.autobackup && parent.config.settings.autobackup.mysqldumppath) { mysqldumpPath = parent.config.settings.autobackup.mysqldumppath; }
1621
+ var cmd = '\"' + mysqldumpPath + '\" --user=\'' + props.user + '\' --password=\'' + props.password + '\'';
1622
+ if (props.host) { cmd += ' -h ' + props.host; }
1623
+ if (props.port) { cmd += ' -P ' + props.port; }
1624
+ cmd += ' meshcentral --result-file=' + ((parent.platform == 'win32') ? '\"nul\"' : '\"/dev/null\"');
1625
+ const child_process = require('child_process');
1626
+ child_process.exec(cmd, { cwd: backupPath }, function(error, stdout, stdin) {
1627
+ try {
1628
+ if ((error != null) && (error != '')) {
1629
+ if (parent.platform == 'win32') {
1630
+ func(1, "Unable to find mysqldump.exe, MySQL/MariaDB database auto-backup will not be performed.");
1631
+ } else {
1632
+ func(1, "Unable to find mysqldump, MySQL/MariaDB database auto-backup will not be performed.");
1633
+ }
1634
+ } else {
1635
+ func();
1636
+ }
1637
+ } catch (ex) { console.log(ex); }
1638
+ });
1639
} else {
1640
func();
1641
}