Home >Database >Mysql Tutorial >mysql 备份

mysql 备份

WBOY
WBOYOriginal
2016-06-07 15:07:431097browse

今天写了一个mysql备份,主要用的是mysqldump工具。需求是每天3点备份某些数据库,保留2天的备份。很简单的需求,如下脚本 #!/bin/sh dbs=$(echo `/usr/bin/mysql -uroot -ppasswd -s -e show databases; |egrep -v performance_schema|information_schema|t

    今天写了一个mysql备份,主要用的是mysqldump工具。需求是每天3点备份某些数据库,保留2天的备份。很简单的需求,如下脚本

 #!/bin/sh
dbs=$(echo `/usr/bin/mysql -uroot -ppasswd -s -e "show databases;" |egrep -v "performance_schema|information_schema|test|mysql"`)
bak_name=`hostname``date '+%Y%m%d%H%M'`
/usr/bin/mysqldump -uroot -ppasswd --single-transaction --databases $dbs > /data/backup/$bak_name.sql && gzip /data/backup/$bak_name.sql
/usr/bin/find /data/backup/ -type f -mtime +2 -exec  rm -f {} \;

crontab设置定时

0 3 * * * /bin/sh /root/script/backup.sh > /dev/null 2>&1

Statement:
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