KingbaseES R3集群备库执行sys_backup.sh物理备份案例

Posted KINGBASE研究院

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了KingbaseES R3集群备库执行sys_backup.sh物理备份案例相关的知识,希望对你有一定的参考价值。

案例说明:
KingbaseES R3的后期版本支持通过sys_backup.sh执行sys_rman的物理备份,实际上是调用了sys_rman_v6的工具做物理备份。本案例是在备库上执行集群的备份,repo目录在备库上,采用cluster模式备份。

数据库版本:

TEST=# select version();
                                                         VERSION                                                         
-------------------------------------------------------------------------------------------------------------------------
 Kingbase V008R003C002B0270 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

集群架构:

# 节点信息
[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 |              | streaming | 0/9000178     | 0/9000178      | 0/9000178      | 0/9000178       |             2 | sync
(1 row)

一、查看集群主机归档配置

=== 由以下可知, KingbaseES R3新版本的备库wal日志在切换时,也会产生归档日志。===

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_
_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 R3的新版本中,当主库日志发生切换时,会对wal日志执行归档;同时备库wal日志也发生切换,并归档。===

1、主库执行日志切换

TEST=#  select sys_switch_xlog();
 SYS_SWITCH_XLOG 
-----------------
 0/B000238
(1 row)

2、备库切换前后日志信息

** 1)切换前**

2)切换后

3)备库日志被归档

五、总结
在KingbaseES R3的新版本中,可以通过sys_backup.sh脚本执行sys_rman的物理备份,实际上是调用了sys_rman_v6的工具执行了物理备份,和KingbaseES R6的sys_rman的备份原理应该是一致的。

以上是关于KingbaseES R3集群备库执行sys_backup.sh物理备份案例的主要内容,如果未能解决你的问题,请参考以下文章

炫“库”行动-人大金仓有奖征文-KingbaseES V8R3 读写分离集群在线扩容案例

炫“库”行动-人大金仓有奖征文-KingbaseES V8R3 读写分离集群在线扩容案例

炫“库”行动-人大金仓有奖征文-KingbaseES V8R3 读写分离集群在线扩容案例

KingbaseES集群管理维护案例之---备库checkpoint分析

KingbaseES R3 集群一键修改集群用户密码

KingbaseES V8R6集群管理运维案例之---repmgr standby switchover故障