[TOC] MySQL全庫備份腳本 ...
目錄
MySQL全庫備份腳本
vim full_database_backup.sh
#!/bin/sh
PATH="/application/mysql/bin:$PATH"
BACKUP1=/backup1
BACKUP2=/backup2
TIME=$(date +"%F:%H:%M:%S")
USER=root
PASS=12345
MYSQL="mysql -u$USER -p$PASS"
MYDUMP="mysqldump -u$USER -p$PASS -A -B -R --master-data=2 --single-transaction"
if [ ! -d $BACKUP1 -o ! -d $BACKUP2 ];then
mkdir $BACKUP1
mkdir $BACKUP2
$MYDUMP |gzip >/$BACKUP1/FULL_${TIME}.tar.gz
cp $BACKUP1/FULL_${TIME}.tar.gz $BACKUP2
echo "您好,您的MySQL數據已全庫備份到${BACKUP2}/FULL_${TIME}.tar.gz"
else
$MYDUMP |gzip >/$BACKUP1/FULL_${TIME}.tar.gz
cp $BACKUP1/FULL_${TIME}.tar.gz $BACKUP2
echo "您好,您的MySQL數據已全庫備份到${BACKUP2}/FULL_${TIME}.tar.gz"
fi
#生產環境:cp換成rsync再扔到crontab上定時運行