Steps for backing up and restoring a MySQL slave server

Source: Internet
Author: User


Today Lesca will describe how to back up and restore MySQL from the server, the platform is still CentOS 7.
Using mysqldump for backup and restore

Using Mysqldump for backup

Mysqladmin stop-slave-uroot-p
Mysqldump--all-databases > Fulldb.dump
Mysqladmin start-slave-uroot-p
tar-czf/tmp/dbdump.tar.gz./fulldb.dump./mysql-relay-log.info

In addition to backing up the entire dump of the database, we also need to back up the Relay-log.info file (the example Mysql-relay-log.info), which contains information similar to the following:

/var/lib/mysql/mysql-relay-bin.000002
720
mysql-bin.000002
3968

The Red highlighted section indicates the execution status of the binary log on the current MySQL master server. This data is critical when restoring from the server.
Using mysqldump to restore

Mysql-uroot-p </root/dbdump.db
Stop slave;
Change MASTER to master_host= ' 192.168.10.201 ', master_user= ' slave_user ', master_password= ' abc@def ', master_log_file= ' mysql-bin.000002 ', master_log_pos=3968;
Start slave;
Show Slave Status\g

In the state, if the following two lines are available, the server is working correctly:

Slave_io_running:yes
Slave_sql_running:yes

Backup and restore using the database file (Raw Data)

Backing Up Database files

Service MARIADB Stop
Tar--selinux--acls--xattrs-czpf/root/dbbackup.tar.gz/var/lib/mysql/
Service MARIADB Start

Note: The red parameter lets tar back up both the SELinux property and other ACL properties to prevent it from being restored to the target server.
Restore Database files

Service MARIADB Stop
Tar--selinux--acls--xattrs-xzpf/root/dbbackup.tar.gz-c/
Service MARIADB Start

Also, you need to specify these parameters when you restore the data files.
Troubleshooting

Error message

150401 9:58:06 [ERROR] mysqld:file '/var/lib/mysql/mysql-bin.index ' not Found (errcode:13)
150401 9:58:06 [ERROR] Aborting

Check SELinux settings

Ll-z Mysql-bin.index
-RW-RW----. MySQL MySQL unconfined_u:object_r:var_lib_t:s0 mysql-bin.index

Solving method

You can disable SELinux (configuration file/etc/selinux/config),
Selinux=disabled

You need to reboot after you have finished modifying it.

You can also add the following parameters to the tar command when compressing and decompressing:
Tar--selinux--acls--xattrs

Expand your knowledge

–selinux–save the SELinux context to the archive
–acls–save the ACLs to the archive
–xattrs–save the User/root xattrs to the archive. IT archives All extended attributes, including SELinux and ACLs.

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.