时间:2021-07-01 10:21:17 帮助过:17人阅读
mysql备份脚本,记录一下:
全备:
#!/bin/sh set -x USER=root PASSWORD=123456 time=`date +"%y-%m-%d-%H-%M"` date >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ #1 begin Full Backups echo "begin backup--------------------------------" >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ /usr/bin/innobackupex --defaults-file=/etc/my.cnf --user=$USER --password=$PASSWORD --use-memory=2GB --parallel=4 --no-timestamp /data/mysqlbackup/full-$time 2>>/data/mysqlbackup/logs/$time‘_allbackup.log‘ cp /etc/my.cnf /data/mysqlbackup/full-$time/my.cnf.bk echo "end backup----------------------------------" >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ #2 begin compress echo "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ archivename=full-$time echo "The archive time is $time" >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ tarname=$archivename.tar.gz echo "The tar name is $tarname" >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ cd /data/mysqlbackup /bin/tar -zcvf ./$tarname ./$archivename >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ 2>&1 rm -rf /data/mysqlbackup/full/xtrabackup_checkpoints cp /data/mysqlbackup/full-$time/xtrabackup_checkpoints /data/mysqlbackup/full/xtrabackup_checkpoints #3 Delete Document file=/data/mysqlbackup/$tarname if [[ -e $file ]] then echo "The $tarname file exists.begin to perform delete action" >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ /bin/rm -rf /data/mysqlbackup/$archivename else echo "The file is not exists." >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ fi date >> /data/mysqlbackup/logs/$time‘_allbackup.log‘ find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I ‘{}‘ mv {} /data/ftp cd /data/ftp function logftp (){ ftp -v -n xxx.xxx.xxx.xxx << EOF user username password binary hash cd ftp_mysql prompt put /data/mysqlbackup/*tar.gz ls -la bye EOF } logftp >>/data/mysqlbackup/logs/to_ftp.log cd /data/ftp find /data/ftp/*tar.gz |xargs rm -rf
增量备份:
#!/bin/sh set -x USER=root PASSWORD=123456 time=`date +"%y-%m-%d-%H-%M"` date >>/data/mysqlbackup/logs/$time‘_incre.log‘ #1 begin Incre Backups echo "begin backup--------------------------------" >> /data/mysqlbackup/logs/$time‘_incre.log‘ /usr/bin/innobackupex --defaults-file=/etc/my.cnf --user=$USER --password=$PASSWORD --incremental --incremental-basedir=/data/mysqlbackup/full --use-memory=2GB --safe-slave-backup --parallel=4 --slave-info --no-timestamp /data/mysqlbackup/incre-$time 2>>/data/mysqlbackup/logs/$time‘_incre.log‘ cp /etc/my.cnf /data/mysqlbackup/incre-$time/my.cnf.bk echo "end backup----------------------------------" >> /data/mysqlbackup/logs/$time‘_incre.log‘ #2 begin compress echo "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time‘_incre.log‘ archivename=incre-$time echo "The archive time is $time" >> /data/mysqlbackup/logs/$time‘_incre.log‘ tarname=$archivename.tar.gz echo "The tar name is $tarname" >> /data/mysqlbackup/logs/$time‘_incre.log‘ cd /data/mysqlbackup/ /bin/tar -zcvf ./$tarname ./$archivename >> /data/mysqlbackup/logs/$time‘_incre.log‘ 2>&1 #3 Delete Document file=/data/mysqlbackup/$tarname if [[ -e $file ]] then echo "The $tarname file exists.begin to perform delete action" >> /data/mysqlbackup/logs/$time‘_incre.log‘ /bin/rm -rf /data/mysqlbackup/$archivename else echo "The file is not exists." >> /data/mysqlbackup/logs/$time‘_incre.log‘ fi date >> /data/mysqlbackup/logs/$time‘_incre.log‘ find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I ‘{}‘ mv {} /data/ftp cd /data/ftp function logftp (){ ftp -v -n xxx.xxx.xxx.xxx << EOF user username password binary hash cd ftp_mysql prompt put /data/mysqlbackup/*tar.gz ls -la bye EOF } logftp >>/data/mysqlbackup/logs/to_ftp.log cd /data/ftp find /data/ftp/*tar.gz |xargs rm -rf
本文出自 “刚刚出壳的小鸟” 博客,请务必保留此出处http://qhd2004.blog.51cto.com/629417/1920346
mysql 备份脚本(xtrabackup)
标签:xtrabackup mysql incr