MySQL全库备份脚本
目录
- 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上定时运行
以上是 MySQL全库备份脚本 的全部内容, 来源链接: utcz.com/z/516024.html