Home > Database > Mysql Tutorial > body text

利用MySQL的mysqlhotcopy实现数据库自动备份的SH脚本源码

WBOY
Release: 2016-06-07 17:17:54
Original
1197 people have browsed it

可以加在cortab 中在每天凌晨1点,备份打包一下MySQL的数据库。backmysql.sh 的文件源码,可以配置备份目录。数据库名 mysqlhotc

可以加在cortab 中在每天凌晨1点,备份打包一下MySQL的数据库。

设定计划任务
--------------------------------------
#crontab -e
0 1 * * * /usr/local/src/backmysql.sh
--------------------------------------

backmysql.sh 的文件源码,可以配置备份目录。数据库名 mysqlhotcopy所在的目录,,以及避免磁盘空间不足删除30日前的备份。

#!/bin/bash
# yum -y install perl-DBD-MySQL  //if mysqlhotcopy can't be runing ,install it
backdir="/usr/local/backup/"
mysqlbindir="/usr/local/mysql/bin/"
backdatabase="cms"
keepdays=30
${mysqlbindir}mysqlhotcopy ${backdatabase} ${backdir}
tar zcvfP ${backdir}${backdatabase}_db_$(date +"%Y%m%d" --date="-1 day").tar ${backdir}${backdatabase}
rm -rf ${backdir}${backdatabase}
rm -rf ${backdir}${backdatabase}_db_$(date +"%Y%m%d" --date="-${keepdays} day").tar

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template