innobackupex 備份MySQL資料庫

gycixput發表於2018-04-17
環境:
rhel 7.2
MySQL:5.6.38

測試innobackupex備份、恢復MySQL過程

--建立測試資料庫
[root@rhel72 mysql]# mysql -uroot -pgyc1234
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.6.38-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)


Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 
mysql> 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.04 sec)


mysql> create database gaoyc;
Query OK, 1 row affected (0.00 sec)


mysql> use gaoyc
Database changed


mysql> show tables;
Empty set (0.00 sec)


mysql> create table gyc as select * from mysql.user;
Query OK, 3 rows affected (0.41 sec)
Records: 3  Duplicates: 0  Warnings: 0


mysql> insert into gyc select * from gyc;
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0
mysql> insert into gyc select * from gyc;
Query OK, 6 rows affected (0.01 sec)
Records: 6  Duplicates: 0  Warnings: 0


mysql> insert into gyc select * from gyc;
Query OK, 12 rows affected (0.00 sec)
Records: 12  Duplicates: 0  Warnings: 0


mysql> insert into gyc select * from gyc;
Query OK, 24 rows affected (0.00 sec)
Records: 24  Duplicates: 0  Warnings: 0


mysql> insert into gyc select * from gyc;
Query OK, 48 rows affected (0.05 sec)
Records: 48  Duplicates: 0  Warnings: 0


mysql> commit;
Query OK, 0 rows affected (0.00 sec)


mysql> create table gyc02 as select * from gyc;
Query OK, 96 rows affected (0.04 sec)
Records: 96  Duplicates: 0  Warnings: 0


mysql> insert into gyc select * from gyc;
Query OK, 96 rows affected (0.05 sec)
Records: 96  Duplicates: 0  Warnings: 0


mysql> commit;
Query OK, 0 rows affected (0.00 sec)




--開始備份
[root@rhel72 backup]# ps -ef | grep mysql
root     16710 14195  0 16:00 pts/3    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
mysql    17002 16710  0 16:00 pts/3    00:00:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/mysqld.log --pid-file=/usr/local/mysql/mysqld.pid --socket=/tmp/mysql.sock --port=3306
root     17078 14165  0 16:01 pts/2    00:00:00 mysql -uroot -px xxxxx
root     17083 14134  0 16:33 pts/0    00:00:00 grep --color=auto mysql
[root@rhel72 backup]# innobackupex -S /tmp/mysql.sock --user=root --password=gyc1234 --no-timestamp /backup/`date +%H-%M`.dbname
180410 16:34:41 innobackupex: Starting the backup operation


IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".


180410 16:34:42  version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;mysql_socket=/tmp/mysql.sock' as 'root'  (using password: YES).
180410 16:34:42  version_check Connected to MySQL server
180410 16:34:42  version_check Executing a version check against the server...
180410 16:34:42  version_check Done.
180410 16:34:42 Connecting to MySQL server host: localhost, user: root, password: set, port: not set, socket: /tmp/mysql.sock
Using server version 5.6.38-enterprise-commercial-advanced-log
innobackupex version 2.4.10 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3198bce)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /usr/local/mysql/data
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following InnoDB configuration:
xtrabackup:   innodb_data_home_dir = .
.......
MySQL binlog position: filename 'mysql-bin.000003', position '4415'
180410 16:34:46 [00] Writing /backup/16-34.dbname/backup-my.cnf
180410 16:34:46 [00]        ...done
180410 16:34:46 [00] Writing /backup/16-34.dbname/xtrabackup_info
180410 16:34:46 [00]        ...done
xtrabackup: Transaction log of lsn (1823795) to (1823795) was copied.
180410 16:34:46 completed OK!


--停止資料庫
[root@rhel72 backup]# /usr/local/mysql/bin/mysqladmin -S /tmp/mysql.sock shutdown -p
Enter password: 




--備份原來資料庫
[root@rhel72 mysql]# tar -cvf data.tar data/
data/
data/mysql/
data/mysql/db.frm
....
[root@rhel72 data]# rm -rf *
[root@rhel72 data]# pwd
/usr/local/mysql/data




--開始恢復
[root@rhel72 backup]# innobackupex --defaults-file=/etc/my.cnf --user=root --apply-log /backup/16-34.dbname
180410 16:36:18 innobackupex: Starting the apply-log operation


IMPORTANT: Please check that the apply-log run completes successfully.
           At the end of a successful apply-log run innobackupex
           prints "completed OK!".


innobackupex version 2.4.10 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3198bce)
xtrabackup: cd to /backup/16-34.dbname/
xtrabackup: This target seems to be not prepared yet.
.....


InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1824296
180410 16:36:29 completed OK!
[root@rhel72 backup]# innobackupex --defaults-file=/etc/my.cnf --user=root --copy-back /backup/16-34.dbname
180410 16:37:08 innobackupex: Starting the copy-back operation


IMPORTANT: Please check that the copy-back run completes successfully.
           At the end of a successful copy-back run innobackupex
           prints "completed OK!".


innobackupex version 2.4.10 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3198bce)
180410 16:37:08 [01] Copying ib_logfile0 to /usr/local/mysql/data/ib_logfile0
......




--調整許可權,開啟資料庫
[root@rhel72 data]# chown -R mysql:mysql ../data
[root@rhel72 data]# /usr/local/mysql/bin/mysqld_safe
180410 16:38:34 mysqld_safe Logging to '/usr/local/mysql/mysqld.log'.
180410 16:38:34 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data




--驗證資料
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| gaoyc              |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.07 sec)


mysql> use gaoyc
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> show tables;
+-----------------+
| Tables_in_gaoyc |
+-----------------+
| gyc             |
| gyc02           |
+-----------------+
2 rows in set (0.00 sec)


mysql> select count(*) from gyc;
+----------+
| count(*) |
+----------+
|      192 |
+----------+
1 row in set (0.08 sec)


mysql> select count(*) from gyc02;
+----------+
| count(*) |
+----------+
|       96 |
+----------+
1 row in set (0.05 sec)


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24585765/viewspace-2153015/,如需轉載,請註明出處,否則將追究法律責任。

相關文章