美文网首页
编写自动备份脚本

编写自动备份脚本

作者: 日落_3d9f | 来源:发表于2019-12-17 11:13 被阅读0次

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

完毕。

相关文章

网友评论

      本文标题:编写自动备份脚本

      本文链接:https://www.haomeiwen.com/subject/zaksnctx.html