shell脚本,mysql数据库的备份,并压缩

db_user="root"
db_passwd="xxx"
db_host="localhost"

databases="xxx-prod"

backup_dir="/backup/mysql_backup"

backip_test="/home/ttx/app/mysql_backup/today"

time="$(date +"%Y-%m-%d")"

test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0

test ! -d "$backup_dir" && mkdir "$backup_dir"

for db in $databases
do
mv /backup/mysql_backup/wms_backup.gz /backup/mysql_backup/$db.$time.gz
mysqldump -h $db_host $db | gzip -9 > "$backup_dir/wms_backup.gz"
done

find $backup_dir -name "*.gz" -mtime +7 |xargs rm -rf
exit 0;

 

posted @ 2018-11-26 14:53  darling331  阅读(198)  评论(0编辑  收藏  举报