From 58ce8db1d03f4509f9f9b167c95e4f3a9bfee05d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 6 May 2024 00:49:48 +0800 Subject: [PATCH] update --- plugins/mongodb/index.py | 15 +++++++++++++-- plugins/mongodb/scripts/backup.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 1163c566b..9db2882bd 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -1260,6 +1260,11 @@ def importDbExternal(): # print(file,name) # print(import_dir,name) + auth = getConfAuth() + mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') + uoption = '' + if auth != 'disabled': + uoption =' -u root -p '+mg_root file_dir = import_dir+name if not os.path.exists(file_dir): @@ -1274,7 +1279,7 @@ def importDbExternal(): bson_list = getListBson(name) # print(bson_list) for x in bson_list: - cmd = getServerDir() + "/bin/mongorestore --port "+str(port)+" --dir "+file_dir+'/'+x + cmd = getServerDir() + "/bin/mongorestore "+uoption+" --port "+str(port)+" --dir "+file_dir+'/'+x # print(cmd) rdata = mw.execShell(cmd) # print(data) @@ -1312,7 +1317,13 @@ def importDbBackup(): # print(cmd) mw.execShell(cmd) - cmd = getServerDir() + "/bin/mongorestore --port "+str(port)+" --dir "+file_dir + auth = getConfAuth() + mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') + uoption = '' + if auth != 'disabled': + uoption =' -u root -p '+mg_root + + cmd = getServerDir() + "/bin/mongorestore "+uoption+" --port "+str(port)+" --dir "+file_dir # print(cmd) mw.execShell(cmd) diff --git a/plugins/mongodb/scripts/backup.py b/plugins/mongodb/scripts/backup.py index 6589f8f7f..386151950 100644 --- a/plugins/mongodb/scripts/backup.py +++ b/plugins/mongodb/scripts/backup.py @@ -37,7 +37,7 @@ def getServerDir(): def getConf(): path = getServerDir() + "/mongodb.conf" return path - + def getConfigData(): cfg = getConf() config_data = mw.readFile(cfg) @@ -137,8 +137,14 @@ class backupTools: backup_name = "mongodb_" + name + "_" + time_now + ".tar.gz" filename = backup_path + "/"+backup_name + port = getConfPort() + auth = getConfAuth() + mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') + uoption = '' + if auth != 'disabled': + uoption =' -u root -p '+mg_root - cmd = db_path + "/bin/mongodump --port 27017 -d test -o "+backup_path + cmd = db_path + "/bin/mongodump "+uoption+" --port "+str(port)+" -d test -o "+backup_path mw.execShell(cmd) cmd_gz = "cd "+backup_path+"/"+name+" && tar -zcvf "+filename + " ./" mw.execShell(cmd_gz)