python备份文件以及mysql数据库的脚本代码
代码如下:
#!/usr/local/python import os import time import string source=['/var/www/html/xxx1/','/var/www/html/xxx2/'] target_dir='/backup/' target=target_dir+time.strftime('%Y%m%d') zip_comm='zip -r %s %s'%(target," ".join(source)) target_database=['DB_name1','DB_name2'] sql_user='root' sql_pwd='xxx' if os.system(zip_comm) == 0: print 'file backup Success is:',target #if python version is 3.x ,print('file backup Success is:',target) else: print 'file backup failed!' for database_name in target_database: target_sql=target_dir+database_name+time.strftime('%Y%m%d')+'.sql' sql_comm='/usr/local/mysql/bin/mysqldump -u %s -p%s %s > %s'%(sql_user,sql_pwd,database_name,target_sql) if os.system(sql_comm) == 0: print database_name,'is backup seccess!' else: print database_name,'is backup Failed!!'
相关推荐
EdwardSiCong 2020-11-23
yungpheng 2020-10-19
jipengx 2020-11-12
橄榄 2020-11-03
lyqdanang 2020-11-02
wservices 2020-10-30
onepiecedn 2020-10-29
数据人 2020-10-26
dfphoto 2020-10-16
hackerlpy 2020-09-07
tianyayi 2020-08-16
Dullonjiang 2020-08-15
fengling 2020-08-15
wordmhg 2020-08-06
guotiaotiao 2020-08-06
zhangsyi 2020-07-28
千锋 2020-07-27
ahnjwj 2020-07-28