本文共 943 字,大约阅读时间需要 3 分钟。
1,在/server/scripts/目录中创建备份脚本mysql_backup.sh
2,vim mysql_backup.sh
#!/bin/bash#---------------------------#Filename: mysql_backup.sh#Revision: 1.4#Date: 2018/09/19#Author: qc#Description: mysql backup every day delete before 7days.#Notes: This plugin uses the "" command#----------------------------#Backup file is saved in the directory, if it does not exist Createbasepath='/data/mysql/backup/'
if [ ! -d "$basepath" ]; then
mkdir -p "$basepath"fi#mysql bakcup to /data/mysql/backup/
/usr/bin/mysqldump -uroot -p'12345678' --events --master-data=0 -B -A|gzip >$basepath/mysqlbak_$(date +%F).sql.gz#Delete the backup data to 7 days before
/usr/bin/find $basepath -mtime +7 -type f -name "*.sql.gz" -exec rm -rf {} \;3,创建定时任务,每天凌晨2点执行此脚本
#crontab -e#注释###### mysqldump backup mysql db ######
0 2 * /bin/sh /server/scripts/mysql_backup.sh &>/dev/null
4,注意事项
先在命令行里面测试,看是否成功,然后再写入定时任务脚本。转载于:https://blog.51cto.com/13718210/2176926