KingbaseES V8R6集群备份恢复案例之--- 主备集群single模式备份

案例说明:
在KingbaseES V8R6主备复制集群在每个节点单独备份(single模式),以sys_backup.sh做物理备份。

适用版本:
KingbaseES V8R6

数据库版本:

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

test=# select version();
                                                       version                                                        
----------------------------------------------------------------------------------------------------------------------
 KingbaseES V008R006C003B0010 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)主库配置

[kingbase@node3 bin]$ cat sys_backup.conf|grep -v ^#|grep -v ^$

_target_db_style="single"
_one_db_ip="192.168.7.243" 
_repo_ip="192.168.7.243"
_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/cluster/R6HA/KHA/kingbase/data"
_single_bin_dir="/home/kingbase/cluster/R6HA/KHA/kingbase/bin"
_single_db_user="system"
_single_db_port="54321"

2)执行初始化

[kingbase@node3 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.

3)查看sys_rman.conf文件

[kingbase@node3 kbbr_repo]$ cat sys_rman.conf 
# Genarate by script at 20210301131324, should not change manually
[kingbase]
kb1-path=/home/kingbase/cluster/R6HA/KHA/kingbase/data
kb1-port=54321
kb1-user=system

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

4)启动脚本备份创建计划任务

[kingbase@node3 bin]$ ./sys_backup.sh start
Enable some sys_rman in crontab-daemon
Set full-backup in 7 days
Set incr-backup in 1 days
0 2 */7 * * kingbase /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman 
--config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >>/tmp/sys_rman_backup_full.log 2>&1
0 4 */1 * * kingbase /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman 
--config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >>/tmp/sys_rman_backup_incr.log 2>&1

5)手工执行全备测试

[kingbase@node3 bin]$ /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf 
--stanza=kingbase --archive-copy --type=full backup >>/tmp/sys_rman_backup_full.log 2>&1

备份日志文件:

[kingbase@node3 bin]$ head -100 /tmp/sys_rman_backup_full.log
2021-03-01 13:18:00.349 P00   INFO: backup command begin 2.27: --archive-copy --compress-level=3 --compress-type=gz --config=/home/kingbase/kbbr_repo/sys_rman.conf --log-level-console=info --log-level-file=info --log-path=/tmp --log-subprocess --kb1-path=/home/kingbase/cluster/R6HA/KHA/kingbase/data --kb1-port=54321 --kb1-user=system --process-max=4 --repo1-path=/home/kingbase/kbbr_repo --repo1-retention-full=5 --stanza=kingbase --type=full
2021-03-01 13:18:00.965 P00   INFO: execute non-exclusive sys_start_backup(): backup begins after the next regular checkpoint completes
2021-03-01 13:18:01.981 P00   INFO: backup start archive = 0000000B0000000400000097, lsn = 4/97000028
WARN: file 'base/16385/1259' has timestamp in the future, enabling delta checksum
2021-03-01 13:18:03.680 P04   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/sys_log/kingbase-2021-03-01_144931.log (5.4MB, 3%) checksum fc5cd6dadd9291b9c20f6c9442f19feb91cf8e50
......


[kingbase@node3 bin]$ tail -100 /tmp/sys_rman_backup_full.log

......
2021-03-01 13:18:35.374 P04   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/base/1/13463 (0B, 100%)
2021-03-01 13:18:35.375 P02   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/base/1/13458 (0B, 100%)
2021-03-01 13:18:35.376 P01   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/base/1/13468 (0B, 100%)
2021-03-01 13:18:35.377 P03   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/base/1/1177 (0B, 100%)
2021-03-01 13:18:35.377 P04   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/.wallet/userkey.kr (0B, 100%)
2021-03-01 13:18:35.378 P02   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/.wallet/tspkey.kr (0B, 100%)
2021-03-01 13:18:35.379 P01   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/.wallet/tbcolkey.kr (0B, 100%)
2021-03-01 13:18:35.379 P00   INFO: full backup size = 158.8MB
2021-03-01 13:18:35.379 P00   INFO: execute non-exclusive sys_stop_backup() and wait for all WAL segments to archive
2021-03-01 13:18:36.182 P00   INFO: backup stop archive = 0000000B0000000400000097, lsn = 4/97000138
2021-03-01 13:18:36.204 P00   INFO: check archive for segment(s) 0000000B0000000400000097:0000000B0000000400000097
2021-03-01 13:18:36.476 P00   INFO: new backup label = 20210301-131800F
2021-03-01 13:18:37.018 P00   INFO: backup command end: completed successfully (36670ms)
2021-03-01 13:18:37.018 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=/tmp --log-subprocess --repo1-path=/home/kingbase/kbbr_repo --repo1-retention-full=5 --stanza=kingbase
2021-03-01 13:18:37.572 P00   INFO: expire command end: completed successfully (554ms)

5)归档日志备份信息

[kingbase@node3 kbbr_repo]$ ls archive/kingbase/12-1/ -l
total 8
drwxr-x--- 2 kingbase kingbase   89 Mar  1 13:13 0000000A00000004
drwxr-x--- 2 kingbase kingbase 4096 Mar  1 13:18 0000000B00000004
-rw-r----- 1 kingbase kingbase  130 Mar  1 13:13 0000000B.history
[kingbase@node3 kbbr_repo]$ date
Mon Mar  1 13:22:03 CST 2021
[kingbase@node3 kbbr_repo]$ ls archive/kingbase/12-1/0000000A00000004 -l
total 76
-rw-r----- 1 kingbase kingbase 74991 Mar  1 13:13 0000000A000000040000008A.partial-9c46e614fec5d8cf356964a63f7f4c21f738f759.gz
[kingbase@node3 kbbr_repo]$ ls archive/kingbase/12-1/0000000B00000004 -l
total 1144
-rw-r----- 1 kingbase kingbase 118140 Mar  1 13:13 0000000B000000040000008A-421487f79655f4790476ae75910e19f20bd2a2e6.gz
.......
-rw-r----- 1 kingbase kingbase    373 Mar  1 13:18 0000000B0000000400000097.00000028.backup
-rw-r----- 1 kingbase kingbase  73395 Mar  1 13:18 0000000B0000000400000097-282e656c58f103626e37f5bdaaa68dc86a627634.gz

查看备份信息:

二、备库备份配置和执行

1)备库备份配置文件

[kingbase@node1 bin]$ cat sys_backup.conf|grep -v ^$|grep -v grep ^#

_target_db_style="single"
_one_db_ip="192.168.7.243" 
_repo_ip="192.168.7.248"
_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/cluster/R6HA/KHA/kingbase/data"
_single_bin_dir="/home/kingbase/cluster/R6HA/KHA/kingbase/bin"
_single_db_user="system"
_single_db_port="54321"

2)备库初始化备份

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

=注意:备库除了用‘sys_backup.sh init cluster_standby',还要用'sys_backup.sh init '做初始化=

[kingbase@node1 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.

3)查看sys_rman.conf配置文件

[kingbase@node1 kbbr_repo]$ cat sys_rman.conf 
# Genarate by script at 20210301132951, should not change manually
[kingbase]
kb1-path=/home/kingbase/cluster/R6HA/KHA/kingbase/data
kb1-port=54321
kb1-user=system
kb1-host=192.168.7.243
kb1-host-user=kingbase

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

4)启动sys_rman.conf备份建立计划任务

[kingbase@node1 bin]$ ./sys_backup.sh start
Enable some sys_rman in crontab-daemon
Set full-backup in 7 days
Set incr-backup in 1 days
0 2 */7 * * kingbase /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf
    --stanza=kingbase --archive-copy --type=full backup >>/tmp/sys_rman_backup_full.log 2>&1
0 4 */1 * * kingbase /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf
 --stanza=kingbase --archive-copy --type=incr backup >>/tmp/sys_rman_backup_incr.log 2>&1

查看计划任务:

[kingbase@node1 cron.d]cat KINGBASECRON
*/1 * * * * kingbase . /etc/profile;/home/kingbase/cluster/R6HA/KHA/kingbase/bin/kbha -A daemon -f /home/kingbase/cluster/R6HA/KHA/kingbase/bin/../etc/repmgr.conf >> /home/kingbase/cluster/R6HA/KHA/kingbase/bin/../kbha.log 2>&1
#*/1 * * * * kingbase  /home/kingbase/cluster/kha/db/bin/network_rewind.sh
#*/1 * * * * root  /home/kingbase/cluster/kha/kingbasecluster/bin/restartcluster.sh
0 2 */7 * * kingbase /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >>/tmp/sys_rman_backup_full.log 2>&1
0 4 */1 * * kingbase /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --
stanza=kingbase --archive-copy --type=incr backup >>/tmp/sys_rman_backup_incr.log 2>&1

执行手工备份:

[kingbase@node1 bin]$ /home/kingbase/cluster/R6HA/KHA/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf 
  --stanza=kingbase --archive-copy --type=full backup >>/tmp/sys_rman_backup_full.log 2>&1

[kingbase@node1 bin]$ head -100 /tmp/sys_rman_backup_full.log
WARN: option 'repo1-retention-full' is not set for 'repo1-retention-full-type=count', the repository may run out of space
      HINT: to retain full backups indefinitely (without warning), set option 'repo1-retention-full' to the maximum.
ERROR: [072]: backup command must be run on the repository host
WARN: option 'repo1-retention-full' is not set for 'repo1-retention-full-type=count', the repository may run out of space
      HINT: to retain full backups indefinitely (without warning), set option 'repo1-retention-full' to the maximum.
ERROR: [072]: backup command must be run on the repository host
2021-03-01 16:09:09.498 P00   INFO: backup command begin 2.27--archive-copy --compress-level=3 --compress-type=gz --config=/home/kingbase/kbbr_repo/sys_rman.conf --log-level-console=info --log-level-file=info --log-path=/tmp --log-subprocess --kb1-path=/home/kingbase/cluster/R6HA/KHA/kingbase/data --kb1-port=54321 --kb1-user=system --process-max=4 --repo1-path=/home/kingbase/kbbr_repo --repo1-retention-full=5 --stanza=kingbase --type=full
2021-03-01 16:09:10.117 P00   INFO: execute non-exclusive sys_start_backup(): backup begins after the next regular checkpoint completes
2021-03-01 16:09:12.428 P00   INFO: backup start archive = 0000000800000002000000A3, lsn = 2/A3000028
WARN: file 'base/16385/16421' has timestamp in the future, enabling delta checksum
2021-03-01 16:09:13.909 P02   INFO: backup file /home/kingbase/cluster/R6HA/KHA/kingbase/data/sys_log/kingbase-2021-03-01_133215.log (6.9MB, 3%) checksum 04ec184eb94f7cb37f4aa3ce7d0ff9ea362b4c7d

三、sys_backup.sh错误案例

=在备库中的sys_backup.conf文件中配置ip为本机ip(非主库ip),执行初始化会提示“无法连接primary错误=

1)查看备份配置文件

[kingbase@node1 bin]$ cat sys_backup.conf|grep -v ^$|grep -v grep ^#

_target_db_style="single"
_one_db_ip="192.168.7.248" 
_repo_ip="192.168.7.248"
_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/cluster/R6HA/KHA/kingbase/data"
_single_bin_dir="/home/kingbase/cluster/R6HA/KHA/kingbase/bin"
_single_db_user="system"
_single_db_port="54321"

2)初始化故障

[kingbase@node1 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)
ERROR: create stanza failed, check log file /tmp/sys_rman_stanza-create.log

3)查看日志

[kingbase@node1 bin]$ cat /tmp/sys_rman_stanza-create.log
2021-03-01 12:36:13.706 P00   INFO: stanza-create command begin 2.27: --config=/home/kingbase/kbbr_repo/sys_rman.conf --log-level-console=info --log-level-file=info --log-path=/tmp --log-subprocess --kb1-path=/home/kingbase/cluster/R6HA/KHA/kingbase/data --kb1-port=54321 --kb1-user=system --repo1-path=/home/kingbase/kbbr_repo --stanza=kingbase
ERROR: [056]: unable to find primary cluster - cannot proceed
2021-03-01 12:36:14.236 P00   INFO: stanza-create command end: aborted with exception [056]

查看备份信息:

posted @   天涯客1224  阅读(471)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示