| 758 | |
| 759 | # 备份数据库 |
| 760 | def backup_database(self, id, log_file): |
| 761 | name = public.M('databases').where("id=?", (id,)).getField('name') |
| 762 | find = public.M('config').where('id=?', (1,)).field( |
| 763 | 'mysql_root,backup_path').find() |
| 764 | |
| 765 | if not os.path.exists(find['backup_path'] + '/database'): |
| 766 | public.ExecShell('mkdir -p ' + find['backup_path'] + '/database') |
| 767 | self.mypass(True, find['mysql_root']) |
| 768 | |
| 769 | fileName = name + '_' + \ |
| 770 | time.strftime('%Y%m%d_%H%M%S', time.localtime()) + '.sql.gz' |
| 771 | backupName = find['backup_path'] + '/database/' + fileName |
| 772 | public.ExecShell("/www/server/mysql/bin/mysqldump --force --opt \"" + |
| 773 | name + "\" | gzip > " + backupName) |
| 774 | if not os.path.exists(backupName): |
| 775 | return public.returnMsg(False, 'BACKUP_ERROR') |
| 776 | |
| 777 | self.mypass(False, find['mysql_root']) |
| 778 | |
| 779 | sql = public.M('backup') |
| 780 | addTime = time.strftime('%Y-%m-%d %X', time.localtime()) |
| 781 | sql.add('type,name,pid,filename,size,addtime', |
| 782 | (1, fileName, id, backupName, 0, addTime)) |
| 783 | public.WriteLog("TYPE_DATABASE", "DATABASE_BACKUP_SUCCESS", (name,),not_web = self.not_web) |
| 784 | return public.returnMsg(True, 'BACKUP_SUCCESS') |
| 785 | |
| 786 | # 导入数据库 |
| 787 | def input_database(self, id, file, log_file): |