MySQL Incremental backup script (innobackupex)

Source: Internet
Author: User

MySQL Incremental backup script (innobackupex)

1. in the online environment, I sometimes write a simple script for Incremental backup of the MySQL database.

2. Add an automatic task and execute it every hour or shorter.

#! /Bin/sh

# Author RuM

# Date 2015-07-10

BAKDIR =/tmp/mysqlbak

BAKDIR_FULL = $ BAKDIR/full

BAKDIR_ADD = $ BAKDIR/add

CONF =/etc/my. cnf

Passswd = 123456

INNOBACKUPEX =/usr/bin/innobackupex

# During the first execution, a full backup and Incremental Backup will be performed. In the future, Incremental Backup will be performed.

If [-f "$ INNOBACKUPEX"]

Then

If [-d "$ BAKDIR"]

Then

Echo "is OK"

Else

Mkdir $ BAKDIR_FULL-p

Mkdir $ BAKDIR_ADD-p

Fi

#### Full backup

Files = 'ls $ BAKDIR_FULL'

If [-z "$ files"]

Then

$ INNOBACKUPEX -- defaults-file = $ CONF -- user = root -- password = $ PASSWD $ BAKDIR_FULL

FULLNAME = $ (dir "$ BAKDIR_FULL ")

$ INNOBACKUPEX -- defaults-file = $ CONF -- user = root -- password = $ PASSWD -- incremental-basedir = $ BAKDIR_FULL/$ FULLNAME/-- incremental $ BAKDIR_ADD

Else

#### Incremental Backup

ADDNAME = $ (ls-lt $ BAKDIR_ADD | sed-n 2p | awk '{print $9 }')

$ INNOBACKUPEX -- defaults-file = $ CONF -- user = root -- password = $ PASSWD -- incremental-basedir = $ BAKDIR_ADD/$ ADDNAME/-- incremental $ BAKDIR_ADD

Fi

Else

Echo "is not install innobackupex"

Fi

This article permanently updates the link address:

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.