Cron Bash AutoBackup Database
Cron Bash AutoBackup Database
备份策略:
每天定时备份数据库一次
备份数据只保留最近三天
Cron 任务编写
10 10 * * * /home/backup_mysql > /tmp/cronjob.txt 2>&1
Bash脚本
#!/bin/bash
# server mysql backup
# backup init
dir=/home/
user=root
pwd=
server=admin
database=
date=`date +%Y_%m_%d`
filename="$server"_"$date".sql
#Script for exec
cd $dir
mysqldump -u $user -p$pwd --skip-lock-tables $database > "$filename"
find $dir -type f -mtime +3 -delete;
注意事项
编写Cron时,注意Server的时区, 用
date
检查下