mysql全備簡單小指令碼
阿新 • • 發佈:2019-05-11
#!/bin/bash # wangyunlong mysqldump to Fully backup mysql data per week! [ -d /home/mysql_mtback/backup ] || mkdir -p /home/mysql_mtback/backup/ [ -d /home/mysql/backup ] || mkdir -p /home/mysql/backup [ -f /home/mysql/backup/bak1.log]|| touch /home/mysql/backup/bak1.log [ -d /root/data ]|| mkdir -p /root/data [ -f /root/data/getdata_mt.log ]|| touch /root/data/getdata_mt.log source /etc/profile Bakip=xxx.xxx.xxx.xxx Bakadmin=root BakDir=/home/mysql_mtback/backup LogFile=/home/mysql/backup/bak1.log Dbackph=/Backup_DB_WEB/Math_DB/Gongwang/DB Date=`date +%Y%m%d` Begin=`date +"%Y年%m月%d日 %H:%M:%S"` cd $BakDir DumpFile=$Date.sql GZDumpFile=$Date.sql.tgz /usr/local/mysql/bin/mysqldump -uroot -pxxx -h127.0.0.1 --quick --events --single-transaction mtmath> $DumpFile /bin/tar -zvcf $GZDumpFile $DumpFile /bin/rm $DumpFile Last=`date +"%Y年%m月%d日 %H:%M:%S"` echo 開始:$Begin 結束:$Last $GZDumpFile succ >> $LogFile echo "(`date`) get data start ..." >> /root/data/getdata_mt.log echo "==============================" >> /root/data/getdata_mt.log /usr/bin/sshpass -p 'xxx' /usr/bin/rsync -avzP -e 'ssh -p 22' --progress $BakDir/$GZDumpFile ${Bakadmin}@${Bakip}:${Dbackph} && /bin/rm -rf