shell脚本如下:
#!/bin/sh
# Database info
DB_USER="qiping"
DB_PASS="Abc1357"
DB_HOST="localhost"
DB_NAME="qiping"
# Others vars
BIN_DIR="/data/mysql/mysql/bin" #the mysql bin path
BCK_DIR="/data/server/backup" #the backup file directory
DATE=`date +%F`
# TODO
# /usr/bin/mysqldump --opt -ubatsing -pbatsingpw -hlocalhost timepusher > /mnt/mysqlBackup/db_`date +%F`.sql
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME > $BCK_DIR/db_$DATE.sql
进入到该脚本文件目录 chmod +x dbback.sh 添加执行权限
编辑定时任务列表
crontab -e
2、插入下面这一行,因为通常来说5点钟网站的访问量最低。
00 05 * * * /bin/sh /usr/local/apache/htdocs/timepusher/sqlBak/sqlAutoBak.sh
#每天早上 5:00am 执行
3、查看任务是否创建成功
crontab -l
完毕。
网友评论