Python Mysql自动备份脚本
时间:2024-01-16 00:57:46
测试系统环境 Windows 2003 python 2.5.1 mysql 5.0.1
应该只适用于Win,因为调用了CMD。
增量备份,因为自用,数据库不大。
回头有了需求加上自检测,5天前的自动删除。
#!/usr/bin/env python
#encoding=utf-8
#Mysql auto backup
#Author: vane
import os, sys, datetime
reload(sys)
sys.setdefaultencoding('utf-8')
backup_path = """d:\\mysql_backup_files"""
dbhost = "localhost"
dbname = "dabatase name" # 数据库名
dbuser = "root" # 用户名
dbuserpw = "123456" # 密码
dbcharset = 'utf8' # 输出文件编码,默认UTF8
now = str(datetime.datetime.now())[:10]
backup_command = """mysqldump -B %s -h%s -u%s -p%s --default_character-set=%s --opt>%s\dbbackup_%s_%s.sql\n""" % (dbname, dbhost, dbuser, dbuserpw, dbcharset, backup_path, dbname, now)
a, b = os.popen2('cmd')
a.write(backup_command)
a.close()
b.read()
b.close()
print "Done!"
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python基础语法之容器详解
![](https://img.aspxhome.com/file/2023/4/121704_0s.jpg)
MySQL执行计划的深入分析
![](https://img.aspxhome.com/file/2023/4/114954_0s.png)
Python环境下安装使用异步任务队列包Celery的基础教程
react-native ListView下拉刷新上拉加载实现代码
![](https://img.aspxhome.com/file/2023/1/137571_0s.gif)
MySQL的命令行提示符及其表达的意思
python GUI模拟实现计算器
![](https://img.aspxhome.com/file/2023/6/66906_0s.jpg)
Python OpenCV超详细讲解透视变换的实现
![](https://img.aspxhome.com/file/2023/7/87977_0s.png)
Python3几个常见问题的处理方法
使用Cython中prange函数实现for循环的并行
![](https://img.aspxhome.com/file/2023/3/76773_0s.png)
Python中将字典转换为XML以及相关的命名空间解析
微信小程序实现简单倒计时功能
![](https://img.aspxhome.com/file/2023/4/136304_0s.jpg)
Python并发编程实例教程之线程的玩法
ASP运行环境iis和pws的搭建
JS前端加密算法示例
适宜做简单搜索的MySQL数据库全文索引
PyQt5 实现字体大小自适应分辨率的方法
向外扩展SQL Server 实现更高扩展性
Python高级特性之切片迭代列表生成式及生成器详解
三达不溜:www
![](https://img.aspxhome.com/file/UploadPic/20093/28/www-43s.png)
JS实现选项卡实例详解
![](https://img.aspxhome.com/file/2023/7/135807_0s.jpg)