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.
26 lines
650 B
26 lines
650 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_%H)-$db.sql
|
|
/usr/bin/mysqldump -ummog -pmmog --master-data=2 --databases $db > $BAKNAME
|
|
|
|
# 将生成的SQL文件压缩
|
|
tar zcvfP $BAKNAME.tgz $BAKNAME
|
|
|
|
# 删除3天之前的备份数据
|
|
find $basepath -mtime +3 -name "*.sql.tgz" -exec rm -rf {} \;
|
|
done
|
|
|
|
# 删除生成的SQL文件
|
|
rm -rf $basepath*.sql
|