首页 > 代码库 > mysql 备份脚本(xtrabackup)
mysql 备份脚本(xtrabackup)
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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。