1. 程式人生 > 其它 >KingbaseES V8R6叢集sys_backup.sh外部備份案例

KingbaseES V8R6叢集sys_backup.sh外部備份案例

案例說明:
本案例採用sys_backup.sh執行物理備份,備份使用如下邏輯架構:叢集採用CentOS 7系統,repo採用kylin V10 Server。

  • 一主一備+外部備份
    此場景為主備雙機常規環境設計,主要的備份資訊來源於備機,極大地減少備份為主機帶來的效能損耗,且增加了第三方專用儲存伺服器,用於存放和管理備份檔案。

  • 叢集節點資訊:

[kingbase@node2 bin]$ ./repmgr cluster show

 ID | Name    | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                                                                                
----+---------+---------+-----------+----------+----------+----------+----------+---------------------------------------------------------------------------------------------------------------------------------------------------
 1  | node200 | primary | * running |          | default  | 100      | 11       | host=192.168.8.200 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
 2  | node201 | standby |   running | node200  | default  | 100      | 11       | host=192.168.8.201 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
  • 資料庫版本:
test=# select version();
                                                       version                                                    
------------------------------------------------------------------------------------------------------------------
 KingbaseES V008R006C005B0023 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 /home/kingbase/cluster/R6C/R6HA/kingbase/

[kingbase@node2 R6HA]$ scp db.zip srv01:/home/kingbase/cluster/R6C/R6HA/kingbase/

# 將叢集db.zip拷貝到repo主機後,解壓
[kingbase@srv01 kingbase]$ ls -lh
total 145M
drwxr-xr-x 2 kingbase kingbase 4.0K Nov  5  2021 bin
-rwx------ 1 kingbase kingbase 145M May 31 12:21 db.zip
drwxrwxr-x 5 kingbase kingbase 8.0K Nov  5  2021 lib
drwxrwxr-x 8 kingbase kingbase 4.0K Nov  5  2021 share

二、初始化備份配置

1、在叢集主備節點配置archive
=archive_command在配置檔案未被註釋時,執行sys_backup.sh init會自動配置=

主庫:
[kingbase@node1 data]$ cat es_rep.conf |grep -i archive_
archive_mode='on'
archive_command='/home/kingbase/cluster/R6C/R6HA/kingbase/bin/sys_rman --config /home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase archive-push %p'
備庫:
[kingbase@node2 data]$ cat es_rep.conf |grep -i archive_
archive_mode='on'
archive_command='/home/kingbase/cluster/R6C/R6HA/kingbase/bin/sys_rman --config /home/kingbase/kbbr_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="cluster"
_one_db_ip="192.168.8.201" 
_repo_ip="192.168.8.100"
_stanza_name="kingbase"  
_os_user_name="kingbase" 
_repo_path="/home/kingbase/kbbr_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"

3、執行sys_backup.sh初始化

[kingbase@srv01 bin]$ ./sys_backup.sh init

The authenticity of host '192.168.8.100 (192.168.8.100)' can't be established.
ECDSA key fingerprint is SHA256:H2wsGtepOaejo4bY8srjnztqrZY/dZosWLDf6m8oUs8.
Are you sure you want to continue connecting (yes/no)? yes
The authenticity of host '192.168.8.100 (192.168.8.100)' can't be established.
ECDSA key fingerprint is SHA256:H2wsGtepOaejo4bY8srjnztqrZY/dZosWLDf6m8oUs8.
Are you sure you want to continue connecting (yes/no)? yes
# generate local sys_rman.conf...DONE
# update all node: sys_rman.conf and archive_command with sys_rman.archive-push...
# update all node: sys_rman.conf and 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.
'sys_backup.sh start' will add CRONTAB items.
Or you can manual backup once with user-guide.

4、檢視初始化配置後的資訊

=注意:對於repo的儲存目錄,在repo和叢集資料節點都會建立,只建立sys_rman.conf,備份儲存在備份伺服器上。=

[kingbase@srv01 ~]$ cd kbbr_repo/
[kingbase@srv01 kbbr_repo]$ cat sys_rman.conf 

# Genarate by script at 20220531122517, should not change manually
[kingbase]
kb1-path=/home/kingbase/cluster/R6C/R6HA/kingbase/data
kb1-port=54321
kb1-user=esrep
kb1-host=192.168.8.200
kb1-host-user=kingbase
kb2-path=/home/kingbase/cluster/R6C/R6HA/kingbase/data
kb2-port=54321
kb2-user=esrep
kb2-host=192.168.8.201
kb2-host-user=kingbase

[global]
repo1-path=/home/kingbase/kbbr_repo
repo1-retention-full=5
log-path=/home/kingbase/cluster/R6C/R6HA/kingbase/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


在叢集節點檢視:

# 主庫:
[kingbase@node1 ~]$ cd kbbr_repo/
[kingbase@node1 kbbr_repo]$ cat sys_rman.conf 
# Genarate by script at 20220531122523, should not change manually
[kingbase]
kb1-path=/home/kingbase/cluster/R6C/R6HA/kingbase/data
[global]
repo1-host=192.168.8.100
repo1-host-user=kingbase
repo1-host-config=/home/kingbase/kbbr_repo/sys_rman.conf
repo1-path=/home/kingbase/kbbr_repo
log-path=/home/kingbase/cluster/R6C/R6HA/kingbase/log
log-level-console=info
log-level-file=info

#備庫:
[kingbase@node2 ~]$ cd kbbr_repo
[kingbase@node2 kbbr_repo]$ cat sys_rman.conf 
# Genarate by script at 20220531122526, should not change manually
[kingbase]
kb1-path=/home/kingbase/cluster/R6C/R6HA/kingbase/data
[global]
repo1-host=192.168.8.100
repo1-host-user=kingbase
repo1-host-config=/home/kingbase/kbbr_repo/sys_rman.conf
repo1-path=/home/kingbase/kbbr_repo
log-path=/home/kingbase/cluster/R6C/R6HA/kingbase/log
log-level-console=info
log-level-file=info

5、初始化的歸檔和資料庫備份資訊
1)歸檔資訊

2)資料庫資訊

3)檢視主庫wal日誌資訊

=由以上資訊,可知,初始化產生備份主要是在主庫上執行了 sys_rman的備份。=

三、執行備份

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 /home/kingbase/cluster/R6C/R6HA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /home/kingbase/cluster/R6C/R6HA/kingbase/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * kingbase /home/kingbase/cluster/R6C/R6HA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /home/kingbase/cluster/R6C/R6HA/kingbase/log/sys_rman_backup_incr.log 2>&1

2、手工測試sys_rman備份

[kingbase@srv01 bin]$ /home/kingbase/cluster/R6C/R6HA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup
......
2022-05-31 12:49:46.041 P04   INFO: backup file 192.168.8.200:/home/kingbase/cluster/R6C/R6HA/kingbase/data/.wallet/tbcolkey.kr (0B, 100%)
2022-05-31 12:49:46.045 P00   INFO: full backup size = 138.2MB
2022-05-31 12:49:46.045 P00   INFO: execute non-exclusive sys_stop_backup() and wait for all WAL segments to archive
2022-05-31 12:49:46.857 P00   INFO: backup stop archive = 0000000B000000010000005B, lsn = 1/5B000128
2022-05-31 12:49:47.558 P00   INFO: check archive for segment(s) 0000000B000000010000005B:0000000B000000010000005B
2022-05-31 12:49:48.930 P00   INFO: new backup label = 20220530-212601F
2022-05-31 12:49:50.223 P00   INFO: backup command end: completed successfully (294166ms)
2022-05-31 12:49:50.224 P00   INFO: expire command begin 2.27: --config=/home/kingbase/kbbr_repo/sys_rman.conf --log-level-console=info --log-level-file=info --log-path=/home/kingbase/cluster/R6C/R6HA/kingbase/log --log-subprocess --kb1-host=192.168.8.200 --kb2-host=192.168.8.201 --kb1-host-user=kingbase --kb2-host-user=kingbase --repo1-path=/home/kingbase/kbbr_repo --repo1-retention-full=5 --stanza=kingbase
2022-05-31 12:49:52.011 P00   INFO: expire command end: completed successfully (1787ms)

3、檢視sys_rman備份資訊

[kingbase@srv01 bin]$ /home/kingbase/cluster/R6C/R6HA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase  info
stanza: kingbase
    status: ok
    cipher: none

    db (current)
        wal archive min/max (V008R006C005B0023-1): 0000000B0000000100000058/0000000B000000010000005B

        full backup: 20220530-210642F
            timestamp start/stop: 2022-05-30 21:06:42 / 2022-05-30 21:12:08
            wal start/stop: 0000000B0000000100000059 / 0000000B0000000100000059
            database size: 144.2MB, backup size: 144.2MB
            repository size: 15.9MB, repository backup size: 15.9MB

        full backup: 20220530-212601F
            timestamp start/stop: 2022-05-30 21:26:01 / 2022-05-30 21:30:50
            wal start/stop: 0000000B000000010000005B / 0000000B000000010000005B
            database size: 154.2MB, backup size: 154.2MB
            repository size: 16.6MB, repository backup size: 16.6MB

四、總結

對於KingbaseES V8R6叢集使用sys_backup.sh執行物理備份,可以使用專門的備份伺服器repo,備份的操作在repo上,但實際上還是通過呼叫sys_rman在叢集節點上完成物理備份。