python备份文件以及mysql数据库的脚本代码

yipeiwu_com6年前Python基础
复制代码 代码如下:

#!/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!!'

相关文章

如何将你的应用迁移到Python3的三个步骤

Python 2.x 很快就要 失去官方支持 了,尽管如此,从 Python 2 迁移到 Python 3 却并没有想象中那么难。我在上周用了一个晚上的时间将一个 3D 渲染器的前端代码...

Python3+Pycharm+PyQt5环境搭建步骤图文详解

Python3+Pycharm+PyQt5环境搭建步骤图文详解

搭建环境: 操作系统:Win10 64bit Python版本:3.7 Pycharm:社区免费版 一、Python3.7安装 下载链接:官网https://www.python.org...

python获取外网IP并发邮件的实现方法

第一步:通过ip138来爬取外网ip 第二步:通过python的smtplib模块和email来发送邮件,具体用法去网上搜索, 下面是代码示例: #!/usr/bin/env pyt...

解决pandas使用read_csv()读取文件遇到的问题

如下: 数据文件: 上海机场 (sh600009) 24.11 3.58...

Python中的单继承与多继承实例分析

本文实例讲述了Python中的单继承与多继承。分享给大家供大家参考,具体如下: 单继承 一、介绍 Python 同样支持类的继承,如果一种语言不支持继承,类就没有什么意义。派生类的定义如...