KingbaseES V8R6备份恢复案例之---单实例部署sys_backup.sh外部备份

案例说明:
本案例采用sys_backup.sh执行物理备份,备份使用如下逻辑架构:数据库主机采用CentOS 7系统,repo采用kylin V10 Server。

单实例+外部备份服务器

备份逻辑架构是,在单实例环境下,通过专用的备份服务器执行sys_backup.sh的物理备份。

备份架构节点信息:

数据库版本信息:

test=# select version();
                                                       version                                                    
------------------------------------------------------------------------------------------------------------------
 KingbaseES V008R006C005B0054 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-
bit
(1 row)

一、备份环境配置

1、首先建立repo和数据库节点之间的ssh互信(kingbase和root用户)

[kingbase@srv01 bin]$ uname -a
Linux srv01 4.19.90-17.ky10.x86_64 #1 SMP Sun Jun 28 15:41:49 CST 2020 x86_64 x86_64 x86_64 GNU/Linux

[kingbase@srv01 bin]$ ssh node1
Last login: Mon May 30 21:21:11 2022
[kingbase@node1 ~]$ 

[root@srv01 ~]# ssh node1
Last login: Mon May 30 21:42:32 2022 from 192.168.8.100
[root@node1 ~]# 

2、在repo节点建立备份相关的目录及文件(不需要安装数据库软件)

=注意:目录结构和数据库节点尽量一致,并且保证sys_backup.sh能在repo节点正常执行。=
此版本数据库节点的目录:

[kingbase@srv01 ~]$  mkdir -p /opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/log

kingbase@node1 zip]$ pwd
/opt/Kingbase/ES/V8R6_054/ClientTools/guitools/DeployTools/zip
[kingbase@node1 zip]$ scp db.zip srv01:/opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/

将集群db.zip拷贝到repo主机后,解压:

[kingbase@srv01 Server]$ ls -lh
total 338M
drwxr-xr-x 2 kingbase kingbase 4.0K May 31 14:56 bin
-rw------- 1 kingbase kingbase 338M May 31 14:14 db.zip
drwxrwxr-x 5 kingbase kingbase 8.0K Apr  7 16:17 lib
drwx------ 2 kingbase kingbase 4.0K May 31 14:59 log
drwxrwxr-x 8 kingbase kingbase 4.0K Apr  7 16:17 share

二、初始化备份配置

1、查看数据库节点的archive_command配置

=注意:此archive_command配置,在kingbase.conf中如果未被注释,在sys_backup.sh init时会自动配置。=

[kingbase@node1 data]$ cat kingbase.conf |grep archive_com
archive_command='export TZ=Asia/Shanghai;/opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/bin/sys_rman --config /home/kingbase/kbbr1_repo/sys_rman.conf --stanza=kingbase archive-push %p'

2、在repo节点配置sys_backup.conf文件

[kingbase@srv01 bin]$ cat sys_backup.conf |grep -v ^$|grep -v ^#
_target_db_style="single"
_one_db_ip="192.168.8.200" 
_repo_ip="192.168.8.100"
_stanza_name="kingbase"  
_os_user_name="kingbase" 
_repo_path="/home/kingbase/kbbr1_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 
_band_width=0
_os_ip_cmd="/sbin/ip"
_os_rm_cmd="/bin/rm"
_os_sed_cmd="/bin/sed"
_os_grep_cmd="/bin/grep"
_single_data_dir="/data/kingbase/v8r6_054/data"
_single_bin_dir="/opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/bin"
_single_db_user="system"
_single_db_port="54322"
_use_scmd=off

3、配置数据库免密登录

[kingbase@node1 ~]$ cat .encpwd
*:*:*:system:MTIzNDU2
*:*:*:esrep:YmVpamluZw==

[kingbase@node1 bin]$ ./ksql -U system test -p 54322
ksql (V8.0)
Type "help" for help.

test=# 

4、执行sys_backup.sh初始化

[kingbase@srv01 bin]$ ./sys_backup.sh init
# generate single sys_rman.conf...DONE
# update single archive_command with sys_rman.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 OK.
'sys_backup.sh start' should be executed when need back-rest feature.

5、查看备份初始化后的配置
=注意:对于repo的存储目录,在repo和数据库节点都会创建,只创建sys_rman.conf文件,备份存储在备份服务器。=

[kingbase@srv01 bin]$ cat /home/kingbase/kbbr1_repo/sys_rman.conf 
# Genarate by script at 20220531145653, should not change manually
[kingbase]
kb1-path=/data/kingbase/v8r6_054/data
kb1-port=54322
kb1-user=system
kb1-host=192.168.8.200
kb1-host-user=kingbase

[global]
repo1-path=/home/kingbase/kbbr1_repo
repo1-retention-full=5
log-path=/opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/log
log-level-file=info
log-level-console=info
log-subprocess=y
process-max=4
#### default gz, support: gz none
compress-type=gz
compress-level=3
band-width=0

三、执行sys_backup.sh备份

1、创建备份计划任务

[kingbase@srv01 bin]$ ./sys_backup.sh start
Enable some sys_rman in crontab-daemon
Authorized users only. All activities may be monitored and reported.
Set full-backup in 7 days
Authorized users only. All activities may be monitored and reported.
Authorized users only. All activities may be monitored and reported.
Authorized users only. All activities may be monitored and reported.
Set incr-backup in 1 days
Authorized users only. All activities may be monitored and reported.
Authorized users only. All activities may be monitored and reported.
0 2 */7 * * kingbase /opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/bin/sys_rman --config=/home/kingbase/kbbr1_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * kingbase /opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/bin/sys_rman --config=/home/kingbase/kbbr1_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/log/sys_rman_backup_incr.log 2>&1

2、手工执行sys_rman备份测试

[kingbase@srv01 ~]$ /opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/bin/sys_rman --config=/home/kingbase/kbbr1_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup
.......
2022-05-31 16:06:13.022 P00   INFO: backup stop archive = 000000010000000000000022, lsn = 0/22000128
2022-05-31 16:06:13.223 P00   INFO: check archive for segment(s) 000000010000000000000022:000000010000000000000022
2022-05-31 16:06:14.409 P00   INFO: new backup label = 20220531-004504F
2022-05-31 16:06:15.475 P00   INFO: full backup size = 460.9MB, file total = 2175
2022-05-31 16:06:15.476 P00   INFO: backup command end: completed successfully (136119ms)
2022-05-31 16:06:15.476 P00   INFO: expire command begin 2.27: --config=/home/kingbase/kbbr1_repo/sys_rman.conf --exec-id=100087-403370e7 --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/log --repo1-path=/home/kingbase/kbbr1_repo --repo1-retention-full=5 --stanza=kingbase
2022-05-31 16:06:15.864 P00   INFO: expire command end: completed successfully (388ms)

3、查看备份信息

[kingbase@srv01 ~]$ /opt/Kingbase/ES/V8R6_054/KESRealPro/V008R006C005B0054/Server/bin/sys_rman --config=/home/kingbase/kbbr1_repo/sys_rman.conf --stanza=kingbase  info
stanza: kingbase
    status: ok
    cipher: none

    db (current)
        wal archive min/max (V008R006C005B0054): 00000001000000000000001E/000000010000000000000022

        full backup: 20220530-233807F
            timestamp start/stop: 2022-05-30 23:38:07 / 2022-05-30 23:40:51
            wal start/stop: 000000010000000000000020 / 000000010000000000000020
            database size: 476.9MB, database backup size: 476.9MB
            repo1: backup set size: 13.4MB, backup size: 13.4MB

        full backup: 20220531-004504F
            timestamp start/stop: 2022-05-31 00:45:04 / 2022-05-31 00:47:16
            wal start/stop: 000000010000000000000022 / 000000010000000000000022
            database size: 476.9MB, database backup size: 476.9MB
            repo1: backup set size: 13.4MB, backup size: 13.4MB

四、总结
对于KingbaseES V8R6 单实例使用sys_backup.sh执行物理备份,可以使用专门的备份服务器repo,备份的操作在repo上,但实际上还是通过调用sys_rman在集群节点上完成物理备份。

posted @ 2022-06-11 08:26  KINGBASE研究院  阅读(255)  评论(0编辑  收藏  举报