Last active
November 23, 2021 03:50
-
-
Save szy0syz/8ce14a4ae80281792b58fdb99cf936ff to your computer and use it in GitHub Desktop.
docker-mysql-backup-shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mysql_user="root" | |
mysql_password="" | |
mysql_host="localhost" | |
mysql_port="3306" | |
mysql_charset="utf8mb4" | |
mysql_database="yn_cbp_owner" | |
remote="47.107.45.167" | |
# 备份文件存放地址(根据实际情况填写) | |
backup_location=/usr/local | |
# 是否删除过期数据 | |
expire_backup_delete="OFF" | |
expire_days=7 | |
backup_time=`date +%Y%m%d%H%M` | |
backup_dir=$backup_location | |
welcome_msg="Welcome to use MySQL backup tools!" | |
backup_filename=$backup_dir/mysql-backup-$mysql_database-$backup_time.gz | |
# 备份指定数据库中数据(此处假设数据库是mysql_backup_test) | |
docker exec -it mysql mysqldump -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -B $mysql_database | gzip > $backup_filename | |
scp -P 33022 $backup_filename root@$remote:/mnt/gtkj/mysql_backup | |
# 删除过期数据 | |
if [ "$expire_backup_delete" == "ON" -a "$backup_location" != "" ];then | |
`find $backup_location/ -type f -mtime +$expire_days | xargs rm -rf` | |
echo "Expired backup data delete complete!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment