标签:date node int res password points table address let
安装
[root@node01 yum.repos.d]# cat percona.repo
[percona]
name = Percona
baseurl = https://mirrors.tuna.tsinghua.edu.cn/percona/release/$releasever/RPMS/$basearch
enabled = 1
gpgcheck = 0
[epel]
name=epelrepo
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch
gpgcheck=0
enable=1
[root@node01 yum.repos.d]# yum list all| grep xtraback -i
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
holland-xtrabackup.noarch 1.1.21-1.el7 epel
percona-xtrabackup.x86_64 2.3.10-1.el7 percona
percona-xtrabackup-22.x86_64 2.2.13-1.el7 percona
percona-xtrabackup-22-debuginfo.x86_64 2.2.13-1.el7 percona
percona-xtrabackup-24.x86_64 2.4.18-1.el7 percona
percona-xtrabackup-24-debuginfo.x86_64 2.4.18-1.el7 percona
percona-xtrabackup-80.x86_64 8.0.9-1.el7 percona
percona-xtrabackup-80-debuginfo.x86_64 8.0.9-1.el7 percona
percona-xtrabackup-debuginfo.x86_64 2.3.10-1.el7 percona
percona-xtrabackup-test.x86_64 2.3.10-1.el7 percona
percona-xtrabackup-test-22.x86_64 2.2.13-1.el7 percona
percona-xtrabackup-test-24.x86_64 2.4.18-1.el7 percona
percona-xtrabackup-test-80.x86_64 8.0.9-1.el7 percona
[root@node01 yum.repos.d]# yum -y install percona-xtrabackup-24
装完xtrabackup后,生成以下几个工具。
[root@node01 yum.repos.d]# rpm -ql percona-xtrabackup-24 | grep bin | xargs ls -hl
lrwxrwxrwx 1 root root 10 2月 4 18:05 /usr/bin/innobackupex -> xtrabackup
-rwxr-xr-x 1 root root 3.7M 12月 15 00:23 /usr/bin/xbcloud
-rwxr-xr-x 1 root root 3.0K 12月 15 00:16 /usr/bin/xbcloud_osenv
-rwxr-xr-x 1 root root 3.5M 12月 15 00:23 /usr/bin/xbcrypt
-rwxr-xr-x 1 root root 3.5M 12月 15 00:23 /usr/bin/xbstream
-rwxr-xr-x 1 root root 21M 12月 15 00:23 /usr/bin/xtrabackup
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> CREATE DATABASE friends; Query OK, 1 row affected (0.00 sec)
mysql> create table test ( -> d int(4), -> name varchar(16) -> )ENGINE=innodb DEFAULT CHARSET=gbk; Query OK, 0 rows affected (0.29 sec)
[root@node01 yum.repos.d]# mkdir -p /opt/backup/ [root@node01 yum.repos.d]# cd /opt/backup/ [root@node01 backup]# mkdir full [root@node01 backup]# mkdir incr [root@node01 backup]# ls full incr [root@node01 backup]#
[root@node01 backup]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=‘Qwer!234‘ --port=3306 /opt/backup/full/ [root@node01 backup]# ls -l full/2020-02-04_18-37-08/ 总用量 12336 -rw-r----- 1 root root 487 2月 4 18:37 backup-my.cnf drwxr-x--- 2 root root 52 2月 4 18:37 friends -rw-r----- 1 root root 425 2月 4 18:37 ib_buffer_pool -rw-r----- 1 root root 12582912 2月 4 18:37 ibdata1 drwxr-x--- 2 root root 4096 2月 4 18:37 mysql drwxr-x--- 2 root root 8192 2月 4 18:37 performance_schema drwxr-x--- 2 root root 8192 2月 4 18:37 sys -rw-r----- 1 root root 135 2月 4 18:37 xtrabackup_checkpoints -rw-r----- 1 root root 468 2月 4 18:37 xtrabackup_info -rw-r----- 1 root root 2560 2月 4 18:37 xtrabackup_logfile
mysql> INSERT INTO test(d, name) VALUES (2, ‘winstom‘ ); Query OK, 1 row affected (0.07 sec) mysql> select * from test; +------+---------+ | d | name | +------+---------+ | 2 | winstom | +------+---------+ 1 row in set (0.00 sec)
第一次增量备份,要以全量备份为节点,进行备份
增量备份使用--incremental
参数加 增量备份的目录。
所以 --incremental-basedir
跟的参数是全量备份的目录
[root@node01 ~]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=‘Qwer!234‘ --incremental /opt/backup/incr/ --incremental-basedir=/opt/backup/full/2020-02-04_18-37-08/
第一次增量备份完成,下面进行查看
[root@node01 ~]# cd /opt/backup [root@node01 backup]# ll incr/2020-02-04_18-46-03/ 总用量 148 -rw-r----- 1 root root 487 2月 4 18:46 backup-my.cnf drwxr-x--- 2 root root 79 2月 4 18:46 friends -rw-r----- 1 root root 425 2月 4 18:46 ib_buffer_pool -rw-r----- 1 root root 98304 2月 4 18:46 ibdata1.delta -rw-r----- 1 root root 60 2月 4 18:46 ibdata1.meta drwxr-x--- 2 root root 4096 2月 4 18:46 mysql drwxr-x--- 2 root root 8192 2月 4 18:46 performance_schema drwxr-x--- 2 root root 8192 2月 4 18:46 sys -rw-r----- 1 root root 139 2月 4 18:46 xtrabackup_checkpoints -rw-r----- 1 root root 536 2月 4 18:46 xtrabackup_info -rw-r----- 1 root root 2560 2月 4 18:46 xtrabackup_logfile
mysql> INSERT INTO test(d, name) VALUES (3, ‘liujunjun‘ ); Query OK, 1 row affected (0.05 sec) mysql> select * from test; +------+-----------+ | d | name | +------+-----------+ | 2 | winstom | | 3 | liujunjun | +------+-----------+ 2 rows in set (0.00 sec)
在第二次增量备份的时候,不再是以全量为节点,要以上一次增量备份为节点来进行第二次的增量备份
所以--incremental-basedir
参数后面跟的是上一次增量备份的目录;
[root@node01 backup]# cd /opt/backup/ [root@node01 backup]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=‘Qwer!234‘ --incremental /opt/backup/incr/ --incremental-basedir=/opt/backup/incr/2020-02-04_18-46-03 [root@node01 backup]# ls incr/2020-02-04_18-51-53/ -l 总用量 116 -rw-r----- 1 root root 487 2月 4 18:51 backup-my.cnf drwxr-x--- 2 root root 79 2月 4 18:51 friends -rw-r----- 1 root root 425 2月 4 18:51 ib_buffer_pool -rw-r----- 1 root root 65536 2月 4 18:51 ibdata1.delta -rw-r----- 1 root root 60 2月 4 18:51 ibdata1.meta drwxr-x--- 2 root root 4096 2月 4 18:51 mysql drwxr-x--- 2 root root 8192 2月 4 18:51 performance_schema drwxr-x--- 2 root root 8192 2月 4 18:51 sys -rw-r----- 1 root root 139 2月 4 18:51 xtrabackup_checkpoints -rw-r----- 1 root root 535 2月 4 18:51 xtrabackup_info -rw-r----- 1 root root 2560 2月 4 18:51 xtrabackup_logfile
[root@node01 2020-02-04_18-37-08]# cat xtrabackup_checkpoints backup_type = full-backuped from_lsn = 0 to_lsn = 2634553 last_lsn = 2634562 compact = 0 recover_binlog_info = 0 flushed_lsn = 2634562 [root@node01 incr]# cat 2020-02-04_18-46-03/xtrabackup_checkpoints backup_type = incremental from_lsn = 2634553 to_lsn = 2634772 last_lsn = 2634781 compact = 0 recover_binlog_info = 0 flushed_lsn = 2634781 [root@node01 incr]# cat 2020-02-04_18-51-53/xtrabackup_checkpoints backup_type = incremental from_lsn = 2634772 to_lsn = 2634958 last_lsn = 2634967 compact = 0 recover_binlog_info = 0 flushed_lsn = 2634967
这里可以看到,全备的lsn是从0开始的,第一次增量备份的lsn是从全量备份的lsn结束的位置开始的,第二次增量备份同理,从第一次增量备份的lsn结束的位置开始的。
mysql> drop database friends; Query OK, 1 row affected (0.49 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
mv
移动到别的目录下;--apply-log
和 --redo-only
参数对全量备份进行恢复前准备操作,如事物回滚等操作;--apply-log
和 --redo-only
参数--apply-log
参数,不要加--redo-only
参数。--copy-back
和 --rsync
参数直接对全量备份操作后的目录进行恢复;[root@node01 incr]# cd /opt/backup/full/ [root@node01 full]# cp -a 2020-02-04_18-37-08/ 2020-02-04_18-37-08.bak [root@node01 full]# cd .. [root@node01 backup]# cd incr/ [root@node01 incr]# ls -l 总用量 0 drwxr-x--- 6 root root 234 2月 4 18:46 2020-02-04_18-46-03 drwxr-x--- 6 root root 234 2月 4 18:51 2020-02-04_18-51-53 [root@node01 incr]# cp -a 2020-02-04_18-46-03/ 2020-02-04_18-46-03.bak [root@node01 incr]# cp -a 2020-02-04_18-51-53/ 2020-02-04_18-51-53.bak
[root@node01 incr]# systemctl stop mysqld [root@node01 incr]# netstat -tuln Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN udp 0 0 127.0.0.1:323 0.0.0.0:* udp6 0 0 ::1:323 :::*
[root@node01 mysql]# ls -l 总用量 110672 -rw-r----- 1 mysql mysql 56 2月 4 18:17 auto.cnf -rw------- 1 mysql mysql 1680 2月 4 18:17 ca-key.pem -rw-r--r-- 1 mysql mysql 1112 2月 4 18:17 ca.pem -rw-r--r-- 1 mysql mysql 1112 2月 4 18:17 client-cert.pem -rw------- 1 mysql mysql 1680 2月 4 18:17 client-key.pem -rw-r----- 1 mysql mysql 14266 2月 4 19:08 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 2月 4 19:08 ibdata1 -rw-r----- 1 mysql mysql 50331648 2月 4 19:08 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 2月 4 18:17 ib_logfile1 drwxr-x--- 2 mysql mysql 4096 2月 4 18:17 mysql drwxr-x--- 2 mysql mysql 8192 2月 4 18:17 performance_schema -rw------- 1 mysql mysql 1680 2月 4 18:17 private_key.pem -rw-r--r-- 1 mysql mysql 452 2月 4 18:17 public_key.pem -rw-r--r-- 1 mysql mysql 1112 2月 4 18:17 server-cert.pem -rw------- 1 mysql mysql 1680 2月 4 18:17 server-key.pem drwxr-x--- 2 mysql mysql 8192 2月 4 18:17 sys [root@node01 mysql]# mv /var/lib/mysql /tmp/
[root@node01 mysql]# innobackupex --apply-log --redo-only /opt/backup/full/2020-02-04_18-37-08/
[root@node01 mysql]# innobackupex --apply-log --redo-only /opt/backup/full/2020-02-04_18-37-08 --incremental-dir=/opt/backup/incr/2020-02-04_18-46-03/
[root@node01 mysql]# cat /opt/backup/full/2020-02-04_18-37-08/xtrabackup_checkpoints backup_type = log-applied from_lsn = 0 to_lsn = 2634772 last_lsn = 2634781 compact = 0 recover_binlog_info = 0 flushed_lsn = 2634781
对比之前查看的第一次增量备份的last_lsn
位置,在应用第一次增量备份到全量后,可以看到last_lsn
已经被应用和第一次全量备份的位置相同了
注意 在引用最后一次增量备份到全量时,不需要增加--redo-only
参数。
[root@node01 mysql]# innobackupex --apply-log /opt/backup/full/2020-02-04_18-37-08 --incremental-dir=/opt/backup/incr/2020-02-04_18-51-53/
[root@node01 mysql]# cat /opt/backup/full/2020-02-04_18-37-08/xtrabackup_checkpoints backup_type = full-prepared from_lsn = 0 to_lsn = 2634958 last_lsn = 2634967 compact = 0 recover_binlog_info = 0 flushed_lsn = 2634967
对比之前查看的第二次增量备份的last_lsn
位置,在应用第二次增量备份到全量后,可以看到last_lsn
已经被应用和第二次全量备份的位置相同了
[root@node01 mysql]# innobackupex --apply-log /opt/backup/full/2020-02-04_18-37-08/
--copy-back
参数恢复拷贝到data目录[root@node01 mysql]# innobackupex --defaults-file=/etc/my.cnf --copy-back /opt/backup/full/2020-02-04_18-37-08/
验证操作
[root@node01 mysql]# ls /var/lib/mysql -l 总用量 122920 drwxr-x--- 2 root root 52 2月 4 19:23 friends -rw-r----- 1 root root 425 2月 4 19:23 ib_buffer_pool -rw-r----- 1 root root 12582912 2月 4 19:23 ibdata1 -rw-r----- 1 root root 50331648 2月 4 19:23 ib_logfile0 -rw-r----- 1 root root 50331648 2月 4 19:23 ib_logfile1 -rw-r----- 1 root root 12582912 2月 4 19:23 ibtmp1 drwxr-x--- 2 root root 4096 2月 4 19:23 mysql drwxr-x--- 2 root root 8192 2月 4 19:23 performance_schema drwxr-x--- 2 root root 8192 2月 4 19:23 sys -rw-r----- 1 root root 535 2月 4 19:23 xtrabackup_info -rw-r----- 1 root root 1 2月 4 19:23 xtrabackup_master_key_id
[root@node01 mysql]# chown -R mysql.mysql /var/lib/mysql [root@node01 mysql]# ls -l 总用量 110672 -rw-r----- 1 mysql mysql 56 2月 4 18:17 auto.cnf -rw------- 1 mysql mysql 1680 2月 4 18:17 ca-key.pem -rw-r--r-- 1 mysql mysql 1112 2月 4 18:17 ca.pem -rw-r--r-- 1 mysql mysql 1112 2月 4 18:17 client-cert.pem -rw------- 1 mysql mysql 1680 2月 4 18:17 client-key.pem -rw-r----- 1 mysql mysql 14266 2月 4 19:08 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 2月 4 19:08 ibdata1 -rw-r----- 1 mysql mysql 50331648 2月 4 19:08 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 2月 4 18:17 ib_logfile1 drwxr-x--- 2 mysql mysql 4096 2月 4 18:17 mysql drwxr-x--- 2 mysql mysql 8192 2月 4 18:17 performance_schema -rw------- 1 mysql mysql 1680 2月 4 18:17 private_key.pem -rw-r--r-- 1 mysql mysql 452 2月 4 18:17 public_key.pem -rw-r--r-- 1 mysql mysql 1112 2月 4 18:17 server-cert.pem -rw------- 1 mysql mysql 1680 2月 4 18:17 server-key.pem drwxr-x--- 2 mysql mysql 8192 2月 4 18:17 sys
[root@node01 mysql]# systemctl start mysqld mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | friends | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.12 sec) mysql> use friends; 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_friends | +-------------------+ | test | +-------------------+ 1 row in set (0.00 sec) mysql> select * from test; +------+-----------+ | d | name | +------+-----------+ | 2 | winstom | | 3 | liujunjun | +------+-----------+ 2 rows in set (0.02 sec)
标签:date node int res password points table address let
原文地址:https://www.cnblogs.com/liujunjun/p/12260581.html