This commit is contained in:
Mr Chen
2024-05-06 00:49:48 +08:00
parent 8b1bf28cf7
commit 58ce8db1d0
2 changed files with 21 additions and 4 deletions
+13 -2
View File
@@ -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)
+8 -2
View File
@@ -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)