MySQL生产库全库备份脚本

时间:2021-12-12 06:01:30

创建一个单独的备份用户backup,不要用root

创建备份目录 :mkdir -p /databackup/fullbackup

mysql> grant SELECT,RELOAD,SHOW DATABASES,SUPER,LOCK TABLES,REPLICATION CLIENT,SHOWVIEW,EVENT,FILE on *.* to backup@'localhost' identified by 'MANAGER';
mysql> flush privileges;
###### 备份数据库的脚本###############
##################
#author rrhelei@126.com#
#######90天备份过期自动删除###########
 
user=backup
passwd=MANAGER
host=localhost
date=Master_db_`date+%Y%m%d%H%M`
mysql_bin=/usr/local/mysql/bin
$mysql_bin/mysqldump-u$user -p$passwd -h$host --single-transaction -A --master-data=2 > /databackup/fullbackup/$date.sql
 
if[   -f /databackup/fullbackup/$date.sql  ]
then
cd  /databackup/fullbackup;tar-cvzf $date.sql.tar.gz $date.sql
rm -fr $date.sql
fi
find /databackup/fullbackup/ -type f -name "*sql*" -mtime +90| xargs rm -fr {};

本文出自 “岁伏” 博客,请务必保留此出处http://suifu.blog.51cto.com/9167728/1758022