#/usr/bin/python
#Created by rs.wang
import sys,os,time
mysql_usr = 'root'
mysql_pwd = 'root'
mysql_db = 'mysql'
mysql_charset = 'gb2312'
bk_path = '/home/wangrs/'
cmd_path = '/usr/bin/'
Logs_path = bk_path + 'Logs'
#log_def
def writeLogs(filename,contents):
f = file(filename,'aw')
f.write(contents)
f.close()
today = bk_path + time.strftime('%Y-%m-%d')
fname = today + os.sep + time.strftime('%H%M%S') + '.gz'
if not os.path.exists(today):
Msg = '-'*30 + time.strftime('%Y-%m-%d,%H:%M:%S') + '-'*30 + 'n'
os.mkdir(today)
Msg += '*success: '+ today + 'nn'
writeLogs(Logs_path,Msg)
else:
Msg = '-'*30 + time.strftime('%Y-%m-%d,%H:%M:%S') + '-'*30 + 'n'
Msg += 'fail' + today + 'fail,nn'
sys.exit()
#################################################################################################
cmd_dump = "%smysqldump -u%s -p%s --default-character-set=%s --opt %s | gzip > %s" %(cmd_path,mysql_user,mysql_pwd,mysql_charset,mysql_db,fname)
if os.system(cmd_dump) == 0:
writeLogs(Logs_path,'data: ' + fname + 'n')
else:
writeLogs(Logs_path,'date_fail! n')
阅读(1745) | 评论(0) | 转发(0) |