MySQL backup script (xtrabackup)

Source: Internet
Author: User
Tags mysql backup

MySQL backup script, record:

Fully prepared:

#!/bin/sh set -x                                                               user=root password=123456time= ' 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.bkecho  "end  Backup----------------------------------" >> /data/mysqlbackup/logs/$time ' _allbackup.log '   #2  begin compress echo  "begin compress------------------------------"  > > /data/mysqlbackup/logs/$time ' _allbackup.log '      archivename=full-$timeecho   "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>&1rm -rf /data/mysqlbackup/full/xtrabackup_checkpoints cp / data/mysqlbackup/full-$time/xtrabackup_checkpoints /data/mysqlbackup/full/xtrabackup_checkpoints#3 delete documentfile=/data/mysqlbackup/$ tarnameif [[ -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 '     fidate >>  /data/mysqlbackup/logs/$time ' _allbackup.log ' find /data/mysqlbackup/*tar.gz -ctime +1| xargs -i  ' {} '   mv  {}  /data/ftpcd /data/ftpfunction logftp   () {ftp -v -n xxx.xxx. xxx.xxx << eofuser username passwordbinaryhashcd ftp_mysqlpromptput /data /mysqlbackup/*tar.gzls -labyeeof}logftp >>/data/mysqlbackup/logs/to_ftp.logcd /data/ Ftpfind /data/ftp/*tar.gz |xargs rm -rf

Incremental Backup:

#!/bin/shset -xuser=rootpassword=123456time= ' date + "%y-%m-%d-%h-%m" ' date >>/data/ mysqlbackup/logs/$time ' _incre.log ' #1  begin Incre Backupsecho  "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.bkecho  "End backup----------------------------------"  > > /data/mysqlbackup/logs/$time ' _incre.log ' #2  begin compressecho  "begin  Compress------------------------------" >> /data/mysqlbackup/logs/$time ' _incre.log '     archivename=incre-$timeecho   "the archive  time is   $time " >> /data/mysqlbackup/logs/$time ' _incre.log '      tarname= $archivename .tar.gzecho  "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 documentfile=/data/mysqlbackup/$tarnameif  [[ -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 '     fidate >>  /data/mysqlbackup/logs/$time ' _incre.log ' find /data/mysqlbackup/*tar.gz -ctime +1|xargs -i   ' {} '   mv  {}  /data/ftpcd /data/ftpfunction logftp  () {FTP  -v -n xxx.xxx.xxx.xxx << EOFuser username passwordbinaryhashcd  ftp_mysqlpromptput /data/mysqlbackup/*tar.gzls -labyeeof}logftp >>/data/mysqlbackup/logs/ To_ftp.logcd /data/ftpfind /data/ftp/*tar.gz |xargs rm -rf


This article is from the "just out of the shell of the Birds" blog, please be sure to keep this source http://qhd2004.blog.51cto.com/629417/1920346

MySQL backup script (xtrabackup)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.