KingbaseES V8R6数据库运维案例之---归档日志批量解析

案例说明:
KingbaseES V8R6数据库的wal日志归档如果通过sys_rman工具执行,默认日志将归档在备份目录下,归档日志被压缩及日志文件名包含随机字符串,在执行sys_waldump时,必须解压缩和改名后才能被识别。

适用版本:

KingbaseES V8R6

一、数据库归档及备份配置

1、归档配置
如下所示,归档通过sys_rman执行:

[kingbase@node201 bin]$ cat ../data/es_rep.conf |grep -i archive_command
archive_command='export TZ=Asia/Shanghai;/home/kingbase/cluster/R6/R6HA/kingbase/bin/sys_rman --config /home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase archive-push %p'

2、备份配置

二、查看归档日志文件

如下所示,归档后日志文件(没有压缩,但是名称有随机字符串):

[kingbase@node201 0000000B00000001]$ pwd
/home/kingbase/kbbr_repo/archive/kingbase/12-1/0000000B00000001

[kingbase@node201 0000000B00000001]$ ls
0000000B00000001000000C1-3886653fdfffa873ac9e9344b5e1c57a88aa75b2
0000000B00000001000000C2-27eeb88a551b185c43aed46275ede4aeffee8be1
0000000B00000001000000C3.00000028.backup
0000000B00000001000000C3-3ffb8d25f1eb9fb9dd7dc2f287a8f7962a662e73

三、执行日志文件解析
如下所示,对于名称中包含随机字符串的日志,解析无法识别:

[kingbase@node201 0000000B00000001]$ /home/kingbase/cluster/R6/R6HA/kingbase/bin/sys_waldump 0000000B00000001000000C1-3886653fdfffa873ac9e9344b5e1c57a88aa75b2
sys_waldump: fatal: could not find file "0000000B00000001000000C1": No such file or directory

四、批量修改日志文件名(如果已压缩,需要先解压)
1、批量改名脚本(基础版)

[kingbase@node201 ~]$ cat f.sh
#!/bin/bash
ARCH_DIR='/home/kingbase/kbbr2_repo/archive/kingbase/12-1/0000000B00000001'
cd $ARCH_DIR
/bin/ls |grep -v backup|grep -v mail >/home/kingbase/f.txt
for fname in `cat /home/kingbase/f.txt`
do
#   echo  $fname
   mv $fname `echo $fname|awk -F '-' '{print $1}'`
#   /bin/ls
done

2、执行脚本改名

[kingbase@node201 ~]$ sh f.sh

# 如下所示,归档日志文件已经被改名
[kingbase@node201 ~]$ ls -lh kbbr2_repo/archive/kingbase/12-1/0000000B00000001/
total 65M
-rw-r----- 1 kingbase kingbase 16M Sep 21 18:29 0000000B00000001000000C4
-rw-r----- 1 kingbase kingbase 16M Sep 21 18:29 0000000B00000001000000C5
-rw-r----- 1 kingbase kingbase 373 Sep 21 18:30 0000000B00000001000000C5.00000028.backup
-rw-r----- 1 kingbase kingbase 16M Sep 21 18:30 0000000B00000001000000C6
-rw-r----- 1 kingbase kingbase 16M Sep 21 18:32 0000000B00000001000000C7

# 归档原文件名
[kingbase@node201 ~]$ cat f.txt
0000000B00000001000000C4-51e4d9f72f86a3265b3382e1a2ea72e44326125b
0000000B00000001000000C5-f38ce0b4d36777e12d89d303468931652e536ef8
0000000B00000001000000C6-c9936249c9e3423ae91002f3a5482283d1e4558a
0000000B00000001000000C7-a81f870590f8337d79e29460b22151873eaae277

五、执行wal日志解析

[kingbase@node201 0000000B00000001]$ /home/kingbase/cluster/R6/R6HA/kingbase/bin/sys_waldump 0000000B00000001000000C1
rmgr: XLOG        len (rec/tot):    114/   114, tx:          0, lsn: 1/C1000028, prev 1/C0020DE0, desc: CHECKPOINT_SHUTDOWN redo 1/C1000028; tli 11; prev tli 11; fpw true; xid 0:1591; oid 49342; multi 1; offset 0; oldest xid 1032 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 0; shutdown
rmgr: Heap        len (rec/tot):     56/  1618, tx:       1591, lsn: 1/C10000A0, prev 1/C1000028, desc: INSERT off 42 flags 0x00, blkref #0: rel 1663/16385/16405 blk 8 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:       1591, lsn: 1/C10006F8, prev 1/C10000A0, desc: COMMIT 2023-09-21 17:32:08.498826 CST
rmgr: Heap        len (rec/tot):     67/   747, tx:       1592, lsn: 1/C1000720, prev 1/C10006F8, desc: HOT_UPDATE off 15 xmax 1592 flags 0x00 ; new off 16 xmax 0, blkref #0: rel 1663/16385/16388 blk 5 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:       1592, lsn: 1/C1000A10, prev 1/C1000720, desc: COMMIT 2023-09-21 17:32:08.650256 CST
........

如下图所示,可以用-p参数批量解析相关目录下wal日志:

六、总结
对于KingbaseES V8R6数据库wal日志在归档,被改名及压缩后,可以通过shell脚本,批量改名,进行wal日志的解析。

posted @ 2023-09-28 14:41  天涯客1224  阅读(8)  评论(0编辑  收藏  举报