You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

29 lines
785 B

#!/bin/bash
# 要备份的数据库名,多个数据库用空格分开
databases=(dbmaccount dbmgame tbill toss)
basepath='/home/mmog/mysql_backup/'
if [ ! -d "$basepath" ]; then
mkdir -p "$basepath"
fi
for db in ${databases[*]}
do
# 备份数据库生成SQL文件
BAKNAME=$basepath$(date +%Y%m%d)-$db.sql
/usr/bin/mysqldump -ummog -pmmog --master-data=2 --databases $db > $BAKNAME
# 将生成的SQL文件压缩
tar zcvfP $BAKNAME.tgz $BAKNAME
# cp到其他机器,双重备份
#scp -P 56000 $basepath$db-$(date +%Y%m%d_%H).sql.tgz mmog@170.106.98.187:/data/mysql_backup_xjp/
# 删除3天之前的备份数据
find $basepath -mtime +3 -name "*.sql.tgz" -exec rm -rf {} \;
done
# 删除生成的SQL文件
rm -rf $basepath*.sql