| 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): |