创建一个单独的备份用户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 {};
©著作权归作者所有:来自51CTO博客作者dbapower的原创作品,如需转载,请注明出处,否则将追究法律责任
mysqlmysql备份脚本全库备份MySQL
共同学习,写下你的评论
评论加载中...
作者其他优质文章