MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / input_database

Method input_database

class/panelTask.py:787–833  ·  view source on GitHub ↗
(self, id, file, log_file)

Source from the content-addressed store, hash-verified

785
786 # 导入数据库
787 def input_database(self, id, file, log_file):
788 name = public.M('databases').where("id=?", (id,)).getField('name')
789 root = public.M('config').where('id=?', (1,)).getField('mysql_root')
790 tmp = file.split('.')
791 exts = ['sql', 'gz', 'zip']
792 ext = tmp[len(tmp) - 1]
793 if ext not in exts:
794 return public.returnMsg(False, 'DATABASE_INPUT_ERR_FORMAT')
795
796 isgzip = False
797 if ext != 'sql':
798 tmp = file.split('/')
799 tmpFile = tmp[len(tmp)-1]
800 tmpFile = tmpFile.replace('.sql.' + ext, '.sql')
801 tmpFile = tmpFile.replace('.' + ext, '.sql')
802 tmpFile = tmpFile.replace('tar.', '')
803 backupPath = public.M('config').where(
804 'id=?', (1,)).getField('backup_path') + '/database'
805
806 if ext == 'zip':
807 public.ExecShell("cd " + backupPath + " && unzip " + file)
808 else:
809 public.ExecShell("cd " + backupPath + " && tar zxf " + file)
810 if not os.path.exists(backupPath + "/" + tmpFile):
811 public.ExecShell("cd " + backupPath +
812 " && gunzip -q " + file)
813 isgzip = True
814
815 if not os.path.exists(backupPath + '/' + tmpFile) or tmpFile == '':
816 return public.returnMsg(False, 'FILE_NOT_EXISTS', (tmpFile,))
817 self.mypass(True, root)
818 public.ExecShell(public.GetConfigValue('setup_path') + "/mysql/bin/mysql -uroot -p" +
819 root + " --force \"" + name + "\" < " + backupPath + '/' + tmpFile)
820 self.mypass(False, root)
821 if isgzip:
822 public.ExecShell('cd ' + backupPath +
823 ' && gzip ' + file.split('/')[-1][:-3])
824 else:
825 public.ExecShell("rm -f " + backupPath + '/' + tmpFile)
826 else:
827 self.mypass(True, root)
828 public.ExecShell(public.GetConfigValue(
829 'setup_path') + "/mysql/bin/mysql -uroot -p" + root + " --force \"" + name + "\" < " + file)
830 self.mypass(False, root)
831
832 public.WriteLog("TYPE_DATABASE", 'DATABASE_INPUT_SUCCESS', (name,),not_web = self.not_web)
833 return public.returnMsg(True, 'DATABASE_INPUT_SUCCESS')
834
835 # 配置
836 def mypass(self, act, root):

Callers 1

execute_taskMethod · 0.95

Calls 9

mypassMethod · 0.95
returnMsgMethod · 0.80
ExecShellMethod · 0.80
getFieldMethod · 0.45
whereMethod · 0.45
MMethod · 0.45
splitMethod · 0.45
replaceMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected