KingbaseES V8R3集群备份恢复案例之---备库执行sys_backup.sh备份
案例说明:
KingbaseES V8R3最新版本支持通过sys_backup.sh脚本,调用sys_rman_v6执行物理备份。本案例描述如何在备库上执行集群的备份,备库作为repo节点,采用cluster模式备份。
适用版本:
KingbaseES V8R3
集群架构:
# 节点信息
[kingbase@node1 ~]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.7.248 node1 # 备库
192.168.7.249 node2
192.168.7.243 node3 # 主库
[kingbase@node3 bin]$ ./ksql -U SYSTEM -W 123456 TEST -p 9999
ksql (V008R003C002B0270)
Type "help" for help.
TEST=# show pool_nodes;
node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+---------------+-------+--------+-----------+---------+------------+-------------------+-------------------
0 | 192.168.7.243 | 54321 | up | 0.500000 | primary | 0 | true | 0
1 | 192.168.7.248 | 54321 | up | 0.500000 | standby | 0 | false | 0
(2 rows)
TEST=# select * from sys_stat_replication;
PID | USESYSID | USENAME | APPLICATION_NAME | CLIENT_ADDR | CLIENT_HOSTNAME | CLIENT_PORT | BACKEND_START | BACKEND_XMIN |
STATE | SENT_LOCATION | WRITE_LOCATION | FLUSH_LOCATION | REPLAY_LOCATION | SYNC_PRIORITY | SYNC_STATE
------+----------+---------+------------------+---------------+-----------------+-------------+-------------------------------+--------------+---
4222 | 10 | SYSTEM | node248 | 192.168.7.248 | | 30369 | 2021-03-01 12:16:20.511199+08 | | st
reaming | 0/9000178 | 0/9000178 | 0/9000178 | 0/9000178 | 2 | sync
(1 row)
一、查看集群主机归档配置
=== 由以下可知,KingbaseES V8R3新版本的备库wal日志在切换时,将会产生归档日志,并且归档日志通过sys_rman备份生成。===
1、主库归档配置
[kingbase@node3 bin]$ cat ../data/kingbase.conf |grep archive_command
archive_command='/home/kingbase/cluster/kha/db/bin/sys_rman_v6 --config /home/kingbase/kbbr3_repo/sys_rman_v6.conf --stanza=kingbase archive-push %p'
# ! waring: if set archive_dest, ignore archive_command.
2、备库归档配置
[kingbase@node1 bin]$ cat ../data/kingbase.conf|grep -i archive_command
archive_command='/home/kingbase/cluster/kha/db/bin/sys_rman_v6 --config /home/kingbase/kbbr3_repo/sys_rman_v6.conf --stanza=kingbase archive-push %p'
# ! waring: if set archive_dest, ignore archive_command.
二、在备库配置sys_backup.conf文件
[kingbase@node1 bin]$ cat sys_backup.conf |grep -v ^#|grep -v ^$
_target_db_style="cluster"
_one_db_ip="192.168.7.243"
_repo_ip="192.168.7.248"
_stanza_name="kingbase"
_os_user_name="kingbase"
_repo_path="/home/kingbase/kbbr3_repo"
_repo_retention_full_count=5
_crond_full_days=7
_crond_diff_days=0
_crond_incr_days=1
_crond_full_hour=2
_crond_diff_hour=3
_crond_incr_hour=4
_os_ip_cmd="/sbin/ip"
_os_rm_cmd="/bin/rm"
_os_sed_cmd="/bin/sed"
_os_grep_cmd="/bin/grep"
_single_data_dir="/home/kingbase/ES/V8_single/data"
_single_bin_dir="/home/kingbase/ES/V8_single/Server/bin"
_single_db_user="system"
_single_db_port="54321"
_kb_pass="S0lOR0JBU0VBRE1JTg=="
二、执行备份初始化
[kingbase@node1 bin]$ ./sys_backup.sh init
# generate local sys_rman_v6.conf...DONE
# update all node: sys_rman_v6.conf and archive_command with sys_rman_v6.archive-push...
# update all node: sys_rman_v6.conf and archive_command with sys_rman_v6.archive-push...DONE
# create stanza and check...(maybe 60+ seconds)
# create stanza and check...DONE
# initial first full backup...(maybe several minutes)
# initial first full backup...DONE
# Initial sys_rman_v6 OK.
'sys_backup.sh start' should be executed when need back-rest feature.
三、查看repo目录及备份信息
[kingbase@node1 ~]$ cd kbbr3_repo/
[kingbase@node1 kbbr3_repo]$ ls -lh
total 4.0K
drwxr-x--- 3 kingbase kingbase 21 Mar 1 12:26 archive
drwxr-x--- 3 kingbase kingbase 21 Mar 1 12:26 backup
-rw-rw-r-- 1 kingbase kingbase 589 Mar 1 12:26 sys_rman_v6.conf
[kingbase@node1 kbbr3_repo]$ ls -lh archive/
total 0
drwxr-x--- 3 kingbase kingbase 61 Mar 1 12:26 kingbase
[kingbase@node1 kbbr3_repo]$ ls -lh backup/
total 0
drwxr-x--- 4 kingbase kingbase 104 Mar 1 12:29 kingbase
[kingbase@node1 kbbr3_repo]$ ls -lh backup/kingbase/
total 8.0K
drwxr-x--- 3 kingbase kingbase 69 Mar 1 12:29 20210301-122305F
drwxr-x--- 3 kingbase kingbase 17 Mar 1 12:29 backup.history
-rw-r----- 1 kingbase kingbase 1.1K Mar 1 12:29 backup.info
-rw-r----- 1 kingbase kingbase 1.1K Mar 1 12:29 backup.info.copy
lrwxrwxrwx 1 kingbase kingbase 16 Mar 1 12:29 latest -> 20210301-122305F
四、测试日志切换归档
=== 由以下测试可以获知,在KingbaseES V8R3的新版本中,当主库日志发生切换时,会对wal日志执行归档;同时备库wal日志也发生切换,并归档。===
1、主库执行日志切换
TEST=# select sys_switch_xlog();
SYS_SWITCH_XLOG
-----------------
0/B000238
(1 row)
2、备库切换前后日志信息
1)切换前
2)切换后
3)备库日志被归档
五、总结
在KingbaseES V8R3的最新版本中,可以通过sys_backup.sh脚调用sys_rman_v6工具执行物理备份,和KingbaseES V8R6环境的sys_rman的备份原理应该是一致的。
KINGBASE研究院