1. 程式人生 > >shell指令碼,mysql資料庫的備份,並壓縮

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;