Test _ MySQL

Source: Internet
Author: User
Test bitsCN.com

Test the accidental deletion operation of MySQL replication + snapshot restoration

The following two scenarios are assumed:

Scenario 1: master-slave architecture with no delay. DBA misoperations: drop database [copy + snapshot: Online Backup]

Scenario 2: There are uncertain or highly risky operations, such as upgrade tests and big table changes. [everything is on the snapshot, so you can delete it if it is not a big deal]

Scenario 2 is relatively simple. if you try to create a new snapshot, you can delete the snapshot and create a new one.

Below we simulate scenario 1

Recovery method:

① Restore snapshots of the Slave Database

② Perform point-in-time recovery based on binlog

Create a snapshot for the standby database first

[root@localhost ~]# vgs  VG   #PV #LV #SN Attr   VSize VFree  vg     4   1   0 wz--n- 3.81G 1.81G[root@localhost ~]# lvs  LV    VG   Attr   LSize Origin Snap%  Move Log Copy%  Convert  mysql vg   -wi-ao 2.00G      [root@localhost ~]# lvcreate --size 1G --snapshot --name backup_mysql /dev/vg/mysql  Logical volume "backup_mysql" created[root@localhost ~]# lvs  LV           VG   Attr   LSize Origin Snap%  Move Log Copy%  Convert  backup_mysql vg   swi-a- 1.00G mysql    0.00                          mysql        vg   owi-ao 2.00G      [root@localhost ~]# mount /dev/vg/backup_mysql  /mnt/backup[root@localhost ~]# cd /mnt/backup/[root@localhost backup]# lslost+found  mysql[root@localhost backup]# tar -jcv -f /mnt/snapshot/mysql.tar.bz2 *[root@localhost ~]# lvremove --force /dev/vg/backup_mysql   Logical volume "backup_mysql" successfully removed

Why do we need to back up the snapshot before restoring it?

First, expensive IO because the head needs to run back and forth in the snapshot zone and system Zone

Second, the snapshot zone space is insufficient, because it is COW principle

On, an experienced DBA mistakenly executed the drop database snapshots command:

Check on the slave database:

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || test               |+--------------------+

The visible database has been deleted.

View and record the current binary log coordinates in the master or slave database.

[mysql@localhost mysql]$ mysqladmin -uroot -poracle shutdown131012 09:59:36 mysqld_safe mysqld from pid file /mnt/lvm/mysql/data/localhost.localdomain.pid ended[1]+  Done                    mysqld_safe[root@localhost ~]# umount /mnt/backup[root@localhost ~]# lvremove --force /dev/vg/backup_mysql   Logical volume "backup_mysql" successfully removed[root@localhost ~]# umount /mnt/lvm                                 [root@localhost ~]# mkfs -t ext3 /dev/vg/mysql[root@localhost ~]# mount /dev/vg/mysql /mnt/lvm[root@localhost ~]# tar -jxv -f /mnt/snapshot/mysql.tar.bz2  -C /mnt/lvm[mysql@localhost ~]$ mysqld_safe &

Execute point-in-time recovery through binlog

[mysql@localhost ~]$ mysqlbinlog --stop-datetime="2013-10-12 10:9:56" /mnt/lvm/mysql/data/mysql-bin.000008 | mysql -uroot -poracle

Confirm data recovery:

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || snapshots          || test               |+--------------------+4 rows in set (0.00 sec)mysql> use snapshots;Database changedmysql> show tables;+---------------------+| Tables_in_snapshots |+---------------------+| t                   |+---------------------+1 row in set (0.00 sec)mysql> select * from t;+----+| id |+----+|  1 |+----+1 row in set (0.00 sec)

By now, the entire simple test is complete.

This copy + snapshot backup architecture can achieve online real-time backup, I personally feel that it is a good backup solution

BitsCN.com

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.