1.开机自动启动备份功能
2.备份文件名按照日期及时间分文件
3.包含存储过程的备份
主要有两个文件:
1.mysqlbackup.py是定时驱动脚本(这里没用cron),内容如下:
---------------------------------------------------------分割线---------------------------------------------------------------------------
import time,os,sys
while 1:
os.system("sh /root/mysql/mysqlbackup.sh")
time.sleep(60*60)
---------------------------------------------------------分割线----------------------------------------------------------------------------
2.mysqlbackup.sh是具体的备份脚本,实现备份表和存储过程,内容如下:
---------------------------------------------------------分割线---------------------------------------------------------------------------
#!/bin/sh
Time=`date +%Y_%m_%d_%H_%M_%S`
mysqldump -uroot -pmysql sns2 -R > /root/mysql/logs/sns2.$Time.sql
---------------------------------------------------------分割线---------------------------------------------------------------------------
3.开机启动备份功能:在/etc/rc.local 文件里面添加下面内容,注意要指定python的可执行文件目录,此处为/usr/bin/python,后面是py脚本的目录:
---------------------------------------------------------分割线---------------------------------------------------------------------------
/usr/bin/python /root/mysql/mysqlbackup.py &
---------------------------------------------------------分割线---------------------------------------------------------------------------