python定时按日期备份MySQL数据并压缩
作者:KimSoft 时间:2024-01-22 11:39:22
本文实例为大家分享了python定时按日期备份MySQL数据并压缩的具体代码,供大家参考,具体内容如下
#-*- coding:utf-8 -*-
import os
import time
import tarfile
import zipfile
'''
mysqldump
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
'''
db_host="localhost"
db_user="root"
db_passwd="root"
db_name="crm"
db_charset="utf8"
db_backup_name=r"c:\crm_%s.sql" %(time.strftime("%Y%m%d%H%M"))
zip_src = db_backup_name
zip_dest = zip_src + ".zip"
def zip_files():
f = zipfile.ZipFile(zip_dest, 'w' ,zipfile.ZIP_DEFLATED)
f.write(zip_src)
f.close()
if __name__ == "__main__":
print("begin to dump mysql database crm...");
os.system("mysqldump -h%s -u%s -p%s %s --default_character-set=%s > %s" %(db_host, db_user, db_passwd, db_name, db_charset, db_backup_name))
print("begin zip files...")
zip_files()
print("done, pyhon is great!")
来源:https://blog.csdn.net/KimSoft/article/details/7461982
标签:python,备份,MySQL
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
AI:如何训练机器学习的模型
2023-01-16 13:18:49
![](https://img.aspxhome.com/file/2023/8/81698_0s.png)
Python编程判断这天是这一年第几天的方法示例
2022-01-30 22:38:19
![](https://img.aspxhome.com/file/2023/8/89378_0s.jpg)
Python基础入门之seed()方法的使用
2021-11-17 04:10:19
Python turtle库绘制菱形的3种方式小结
2022-04-10 14:08:19
![](https://img.aspxhome.com/file/2023/3/124773_0s.jpg)
python实现三种随机请求头方式
2022-01-17 17:06:39
![](https://img.aspxhome.com/file/2023/5/81575_0s.png)
Python编写车票订购系统 Python实现快递收费系统
2023-06-26 15:37:26
![](https://img.aspxhome.com/file/2023/1/126971_0s.jpg)
python实现希尔密码加密的示例代码
2022-06-16 07:55:31
Blender Python编程实现程序化建模生成超形示例详解
2023-06-14 14:38:53
![](https://img.aspxhome.com/file/2023/8/128518_0s.png)
Python知识点详解之正则表达式语法
2022-02-08 17:01:31
使用python远程操作linux过程解析
2021-12-01 21:05:27
详解在OpenCV中如何使用图像像素
2022-05-04 16:05:08
![](https://img.aspxhome.com/file/2023/2/127782_0s.jpg)
Python3字符串学习教程
2023-04-21 10:51:06
Python实现脚本锁功能(同时只能执行一个脚本)
2023-10-03 00:55:51
![](https://img.aspxhome.com/file/2023/0/127700_0s.png)
Pytorch中的variable, tensor与numpy相互转化的方法
2021-08-16 13:59:50
![](https://img.aspxhome.com/file/2023/5/101625_0s.png)
sql server对字段的添加修改删除、以及字段的说明
2012-01-05 18:50:52
python实现定时同步本机与北京时间的方法
2021-03-24 10:58:14
详解java调用ffmpeg转换视频格式为flv
2024-01-19 03:13:11
MySQL的root帐户密码重置方法
2007-08-24 15:53:00
python追加元素到列表的方法
2023-07-08 14:29:47
Python3.5实现的罗马数字转换成整数功能示例
2023-02-18 21:17:32
![](https://img.aspxhome.com/file/2023/0/97500_0s.png)