美文网首页
Linux下MySQL备份以及crontab定时备份

Linux下MySQL备份以及crontab定时备份

作者: 微笑_a8a0 | 来源:发表于2021-06-01 10:53 被阅读0次

1.编写一个备份shell脚本mysql_back.sh

!/bin/sh

File: /root/mysql_dump/mysql_back.sh

Database info

DB_NAME="dezhong_new"
DB_USER="root"
DB_PASS="Biandan@123"

Others vars

whereis mysqldump

IS ` but not '

BIN_DIR="/usr/bin"
BCK_DIR="/root/mysql_dump/data"
DATE=date +%Y%m%d_%H%M%S

TODO

mkdir -p BCK_DIRBIN_DIR/mysqldump --opt -uDB_USER -pDB_PASS $DB_NAME \

BCK_DIR/DB_NAME.dump_$DATE.sql

2.crontab 定时备份

添加到crontab

crontab -e

添加一行,root用户不需要指定执行的用户名,ESC,wq

表示每天8点和16点执行备份脚本

0 8,16 * * * /root/mysql_dump/mysql_back.sh

重启crontab服务

service crond restart

3.数据库还原
mysql -uroot -pBiandan@123 dezhong_new < /dezhong_new.dump_20210601_085549.sql

相关文章

网友评论

      本文标题:Linux下MySQL备份以及crontab定时备份

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