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