备份MySQL数据库

自动备份MySQL数据库,新建backup_mysql.sh脚本:
vi /dir/to/backup_mysql.sh

#!/bin/sh
DB_USER="batsing" DB_PASS="batsingpw" DB_HOST="localhost" DB_NAME="timepusher"
BIN_DIR="/usr/bin" #the mysql bin path BCK_DIR="/mnt/mysqlBackup" #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
#创建定时任务 crontab –e
#每天4点备份数据库 0 4 * * * /dir/to/backup_mysql.sh

你可能感兴趣的:(备份MySQL数据库)