上山打老虎 发表于 2021-7-3 21:40:40

MySQL生产库全库备份脚本


创建一个单独的备份用户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';
  



###### 备份数据库的脚本###############
##################
#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 {};  


  
页: [1]
查看完整版本: MySQL生产库全库备份脚本