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

Method backup_database

class/panelTask.py:760–784  ·  view source on GitHub ↗
(self, id, log_file)

Source from the content-addressed store, hash-verified

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

Callers 1

execute_taskMethod · 0.95

Calls 10

mypassMethod · 0.95
ExecShellMethod · 0.80
returnMsgMethod · 0.80
getFieldMethod · 0.45
whereMethod · 0.45
MMethod · 0.45
findMethod · 0.45
fieldMethod · 0.45
existsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected