Home  >  Article  >  Database  >  mysql工具备份脚本_MySQL

mysql工具备份脚本_MySQL

WBOY
WBOYOriginal
2016-06-01 13:32:241071browse

bitsCN.com

mysql工具备份脚本

 

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

 

 #!/bin/shdbs=$(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

bitsCN.com
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