Use Xtrabackup to back up and restore the database,

Source: Internet
Author: User
Tags percona

Use Xtrabackup to back up and restore the database,

Install Xtrabackup

wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.9/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpmyum install percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpm
Note: backup source files cannot be directly used for restoration and recovery in the production environment. You must copy one copy separately for restoration. 1. Full backup and restoration.

1. Back up the database

innobackupex --user=root --password=li123456 /backups

2. Database destruction

rm -rf /app/mysqldb/*

3. Restore the database

Systemctl stop mysqld # stop the service
Innobackupex -- apply-log/backups/2018-03-05_18-11-28/# sort out the backup
Innobackupex -- copy-back/backups/2018-03-05_18-11-28/# restore the database. Make sure that the database directory is empty before restoration.
Chown-R mysql. mysql/app/mysqldb/# Fix owner Group
Systemctl start mysqld # start the service

 

 

Ii. Full and Incremental backup and Restoration

1. Full backup of the database

innobackupex --user=root --password=li123456 /backups/

 

2. Modify the database and perform Incremental Backup

MariaDB [(none)]> create database ceshi;

 

Mkdir/backups/inc1 # create a directory for storing the first incremental backup to facilitate innobackupex -- user = root -- password = li123456 -- incremental/backups/inc1 -- incremental-basedir =/backups/2018-03-07_15-23-30

 

 

MariaDB [(none)]> drop database test ;

 

Mkdir/backups/inc2 # create a directory for storing the second Incremental Backup
Innobackupex -- user = root -- password = li123456 -- incremental/backups/inc2 -- incremental-basedir =/backups/inc1/2018-03-07_15-42-56

 

3. Database destruction

rm -rf /app/mysqldb/*

4. Restore the database

Systemctl stop mysqld # stop the service
Innobackupex -- apply-log -- redo-only/backups/2018-03-07_15-23-30/# complete backup
Innobackupex -- apply-log -- redo-only/backups/2018-03-07_15-23-30/-- incremental-dir =/backups/inc1/2018-03-07_15-42-56 # sort out the first incremental Backup
Innobackupex -- apply-log -- redo-only/backups/2018-03-07_15-23-30/-- incremental-dir =/backups/inc2/2018-03-07_16-00-17 # sort out the second incremental Backup
Innobackupex -- copy-back/backups/2018-03-07_15-23-30/# restore the database. Make sure that the database directory is empty before restoration.
Chown-R mysql. mysql/app/mysqldb/# Fix owner Group
Systemctl start mysqld # start the service

 

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.