python備份文件以及mysql數(shù)據(jù)庫的腳本代碼
更新時間:2013年06月10日 01:37:20 作者:
最近正在學(xué)習python,看了幾天了,,所以寫個小腳本練習練習,沒什么含金量,只當練手
復(fù)制代碼 代碼如下:
#!/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!!'
相關(guān)文章
基于python內(nèi)置函數(shù)與匿名函數(shù)詳解
下面小編就為大家分享一篇基于python內(nèi)置函數(shù)與匿名函數(shù)詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01python調(diào)用API實現(xiàn)智能回復(fù)機器人
這篇文章主要為大家詳細介紹了python調(diào)用API實現(xiàn)智能回復(fù)機器人,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04對tensorflow 的模型保存和調(diào)用實例講解
今天小編就為大家分享一篇對tensorflow 的模型保存和調(diào)用實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07Python中schedule模塊定時任務(wù)的使用方法(2)
這篇文章主要介紹了Python中schedule模塊定時任務(wù)的使用方法,文章基于上一篇文章的內(nèi)容展開的后續(xù),需要的朋友可以參考一下2022-05-05