当前位置: 技术问答>linux和unix
linux mysql数据库如何自动备份呢?
来源: 互联网 发布时间:2017-03-04
本文导语: mysqlbackup.sh 文件内容是 #!/bin/sh # File: /home/test/dbbackup/mysqlbackup.sh # Database info DB_NAME="xinqq163" DB_USER="root" DB_PASS="root" # Others vars BIN_DIR="/usr/local/mysql/bin" BCK_DIR="/home/test/dbbackup" DATE=`date +%F` # TODO $BIN_DIR/mysqldump --opt ...
mysqlbackup.sh 文件内容是
#!/bin/sh
# File: /home/test/dbbackup/mysqlbackup.sh
# Database info
DB_NAME="xinqq163"
DB_USER="root"
DB_PASS="root"
# Others vars
BIN_DIR="/usr/local/mysql/bin"
BCK_DIR="/home/test/dbbackup"
DATE=`date +%F`
# TODO
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS $DB_NAME | gzip > $BCK_DIR/xinqq163_$DATE.gz
crontab文件下的内容是:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
*/1 * * * * root /home/test/dbbackup/mysqlbackup.sh
我弄了上面的备份不成功,怎么做MYSQL数据库自动备份了呢
#!/bin/sh
# File: /home/test/dbbackup/mysqlbackup.sh
# Database info
DB_NAME="xinqq163"
DB_USER="root"
DB_PASS="root"
# Others vars
BIN_DIR="/usr/local/mysql/bin"
BCK_DIR="/home/test/dbbackup"
DATE=`date +%F`
# TODO
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS $DB_NAME | gzip > $BCK_DIR/xinqq163_$DATE.gz
crontab文件下的内容是:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
*/1 * * * * root /home/test/dbbackup/mysqlbackup.sh
我弄了上面的备份不成功,怎么做MYSQL数据库自动备份了呢
|
1、手动执行你的备份脚本 /home/test/dbbackup/mysqlbackup.sh
看一下能否正确执行,如果不能执行,贴出执行结果
实在不行sh -x /home/test/dbbackup/mysqlbackup.sh 调试你的脚本
2、修改你的crontab
*/1 * * * * root /home/test/dbbackup/mysqlbackup.sh
上边语句的意思是每分钟执行一次mysqlbackup.sh脚本,
3、如果手动执行没有问题,就放到crontab中执行,
看一下能否正确执行,如果不能执行,贴出执行结果
实在不行sh -x /home/test/dbbackup/mysqlbackup.sh 调试你的脚本
2、修改你的crontab
*/1 * * * * root /home/test/dbbackup/mysqlbackup.sh
上边语句的意思是每分钟执行一次mysqlbackup.sh脚本,
3、如果手动执行没有问题,就放到crontab中执行,
|
脚本无误的情况下,实在不行的话,就在脚本(*.sh)里面加入:
source ~/.bash_profile
source ~/.bash_profile