python(2.6适用)备份mysql数据库
http://www.cnblogs.com/hzhida/archive/2012/08/02/2620525.html#!/usr/bin/env pythonimport sys,os,timemysql_usr='chenjuan'mysql_pwd='123456'mysql_db='news'mysql_charset='utf8'today='./backup
·
http://www.cnblogs.com/hzhida/archive/2012/08/02/2620525.html
#!/usr/bin/env python
import sys,os,time
mysql_usr='chenjuan'
mysql_pwd='123456'
mysql_db='news'
mysql_charset='utf8'
today='./backup/'
logs_path='Logs.txt'
def writeLogs(filename,contents):
f=file(filename,'a')
f.write(contents)
f.close()
fname=today+os.sep+time.strftime('%H%M%S')+'.txt'
if not os.path.exists(today):
Msg='-'*30+time.strftime('%Y-%m-%d,%H:%M:%S')+'-'*30+'n'
if(os.mkdir(today))==None:
Msg+='**succeed to create dir:'+today+'nn'
writeLogs(logs_path,Msg)
else:
Msg+='!!create backup dir:'+today+'failed,check whether dir can write! nn'
writeLogs(logs_path,Msg)
#sys.exit()
cmd_dump='mysqldump -u%s -p%s %s > %s' %(mysql_usr,mysql_pwd,mysql_db,fname)
if os.system(cmd_dump)==0:
writeLogs(logs_path,'database backup: '+fname+'\n')
else:
writeLogs(logs_path,'database backup failed! \n')
更多推荐
已为社区贡献5条内容
所有评论(0)