Home > Database > Mysql Tutorial > body text

mysql工具备份脚本_MySQL

WBOY
Release: 2016-06-01 13:32:24
Original
1070 people have browsed it

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 {} /;
Copy after login

 

 

crontab设置定时

 

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

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