mysql 自动备份脚本

#!/bin/bash
#MySQL User Information
USERNAME=root              #用户
PASSWORD=mypasswor    #密码

#Back file
FILE_PREFIX=MySQL_

#Back directory
BACKUP_DIR=/var/bak/sql/         #备份的目录

#MySQL directory
MYSQL_DIR=/web/mysql/bin        #mysql目录

#Date Format
DATE=`date +%Y%m%d`                 #时间

#MySQL database                          #要备份的库名,可多添加
MYSQL1=games
MYSQL2=static

#Go to the backup directory
cd ${BACKUP_DIR}


#The first instance of the backup
if [ -f ${MYSQL1}_${DATE}.sql ]; then
echo MySQL Database ${MYSQL1} ${DATE} backup file already exists.
else
${MYSQL_DIR}/mysqldump -u ${USERNAME} -p${PASSWORD} ${MYSQL1} > ${MYSQL1}_${DATE}.sql
fi

#The second instance of the backup
if [ -f ${MYSQL2}_${DATE}.sql ]; then
echo MySQL Database ${MYSQL2} ${DATE} backup file already exists.
else
${MYSQL_DIR}/mysqldump -u ${USERNAME} -p${PASSWORD} ${MYSQL2} > ${MYSQL2}_${DATE}.sql
fi

你可能感兴趣的:(数据库,mysql,备份,脚本,自动备份)