你的位置:首页 > 操作系统

[操作系统]Linux下mysql自动备份

#!/bin/bash
DATE=`date +%Y-%m-%d-%H:%M -d -3minute`
USER=root
PASSWORD=maybo
BACKUP_DIR='/home/mysqlbak/'
LOG_DIR='/home/mysqlbak/mysqlbak_log.log'
DATABASES='BBS'
if [ ! -d $BACKUP_DIR ];then
mkdir -p $BACKUP_DIR
fi
echo -e "\n" >> $LOG_DIR
echo -e "----------------------------------------------------------" >> $LOG_DIR
echo -e "BACKUP DATA:$DATE" >> $LOG_DIR
echo -e "----------------------------------------------------------" >> $LOG_DIR
cd $BACKUP_DIR
for name in $DATABASES;do
mysqldump -u$USER -p$PASSWORD -R $name > $BACKUP_DIR$DATE'_'$name'.sql'
if [ $? == 0 ];then
echo $BACKUP_DIR$DATE'_'$name'.sql BACKUP SUCCESS.' >> $LOG_DIR
else
echo $BACKUP_DIR$DATE'_'$name'.sql BACKUP FAIL.' >> $LOG_DIR
fi
done