定时备份docker部署的mysql数据
1.新建脚本,添加脚本内容
vi mysql_backup_test_backup.sh
#!/bin/bash # 设置mysql的登录用户名和密码(根据实际情况填写) mysql_user="root" mysql_password="root" mysql_host="localhost" mysql_port="3306" mysql_charset="utf8mb4" # 备份文件存放地址(根据实际情况填写) backup_location=/usr/local # 是否删除过期数据 expire_backup_delete="ON" expire_days=7 backup_time=`date +%Y%m%d%H%M` backup_dir=$backup_location welcome_msg="Welcome to use MySQL backup tools!" # 备份指定数据库中数据(此处假设数据库是mysql_backup_test) docker exec -it mysql mysqldump -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -B test1 > $backup_dir/mysql_backup_test-$backup_time.sql # 删除过期数据 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
2.新建定时任务
#新建定时任务命令crontab -e#查看定时任务命令crontab -l#删除所有定时任务命令crontab -r
43 11,23 * * * cd /root/mysql/conf;sh mysql_backup_test_backup.sh >> log.txt 2>>log.txt
相关推荐
emmm00 2020-11-17
王艺强 2020-11-17
aydh 2020-11-12
世樹 2020-11-11
zry 2020-11-11
URML 2020-11-11
spurity 2020-11-10
yifangs 2020-10-13
Andrea0 2020-09-18
Ida 2020-09-16
ltd00 2020-09-12
tufeiax 2020-09-03
xjd0 2020-09-10
greatboylc 2020-09-10
adsadadaddadasda 2020-09-08
疯狂老司机 2020-09-08
CoderToy 2020-11-16
ribavnu 2020-11-16
bianruifeng 2020-11-16