评论

收藏

[MySQL] MySQL生产库全库备份脚本

数据库 数据库 发布于:2021-07-03 21:40 | 阅读数:558 | 评论:0


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


  
关注下面的标签,发现更多相似文章