欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

MySQL全库备份脚本

程序员文章站 2022-04-15 21:56:18
[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上定时运行