Example of innobackupex used to back up and restore a MySQL database

Source: Internet
Author: User
Tags mkdir mysql database

Background:

In some technical groups, we can see that some O & M personnel still use commands such as mysqldump to back up MySQL, so we feel it is necessary to introduce innobackupex.
Currently, most MySQL-based scenarios use the Master-Slave architecture. Compared with mysqldump, innobackupex backup has the following benefits:
1. Data files are used as backup objects and file-level backup is fast. This is especially suitable for scenarios where all data needs to be backed up;
2. Hot backup will not affect access to existing databases;
3. Record binlog and replication-related information, which is useful when creating and recovering Slave;

The following are some supplements from Feng Ge:
1. innobackupex can be used for online backup of non-stop services, provided that tables are locked for the innodb engine and myisam;
2. in the backup process, IO is high. We recommend that you back up data on a server load balancer instance (I usually use a server load balancer instance for backup only). We do not recommend that you back up data on the Master instance. 3. innobackupex can be used in combination with incremental and full backup;

Use cases:

Environment introduction

Architecture: Master-Slave
MySQL Port 3308
Configuration File:/etc/my_3308.cnf
Backup Directory:/mysql-backup/3308
MySQL data directory:/opt/mysql_3308/data
Service script:/etc/init. d/mysql_3308
Back up data on the Master

# Innobackupex -- defaults-file =/etc/my_3308.cnf/mysql-backup/3308 -- user = backup-user -- password = backup-user -- no-lock
Back up on Slave

# Innobackupex -- defaults-file =/etc/my_3308.cnf/mysql-backup/3308 -- user = backup-user -- password = backup-user -- no-lock -- slave-info -- safe- slave-backup
Restore on Master

#/Etc/init. d/mysql_3308 stop

# Mv/opt/mysql_3308/data/opt/mysql_3308/data_broken
# Mkdir/opt/mysql_3308/data

# Innobackupex -- apply-log/mysql-backup/2015-01-12_08-00-10
# Innobackupex -- copy-back/mysql-backup/2015-01-12_08-00-10 -- defaults-file =/etc/my_3308.cnf

# Chown-R mysql: mysql/opt/mysql_3308/data

#/Etc/init. d/mysql_3308 start
Restore on Slave

#/Etc/init. d/mysql_3308 stop

# Mv/opt/mysql_3308/data/opt/mysql_3308/data_broken
# Mkdir/opt/mysql_3308/data

# Innobackupex -- apply-log/mysql-backup/2015-01-12_08-00-10
# Innobackupex -- copy-back/mysql-backup/2015-01-12_08-00-10 -- defaults-file =/etc/my_3308.cnf

# Chown-R mysql: mysql/opt/mysql_3308/data

#/Etc/init. d/mysql_3308 start

# Cd/opt/mysql_3308/data
# Cat xtrabackup_binlog_pos_innodb
./Bin-log-mysqld.000222 222333

# Mysql_3308-uroot-p

Mysql> change master
Master_host = 'master _ host ',
Master_port = 3308,
Master_user = 'master _ user ',
Master_password = 'master _ password ',
Master_log_file = 'bin-log-mysqld.000222 ',
Master_log_pos = 222333;

Mysql> start slave;

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.