暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

KingbaseES sys_rman物理备份还原工具详解

1052

介绍

sys_rman是KingbaseES 数据库的物理备份工具,与常见的物理备份工具功能类似,支持全量、增量。也可以使用三方专用存储服务器进行备份。

备份架构

其备份架构比较灵活,常见有4种。

1、单机+内部备份 备份服务器和数据库在同一台机器

2、单机+外部备份 备份服务器和数据库在不同机器

3、一主一备+内部备份 备份服务器和数据库在主节点,归档日志从备节点复制

4、一主一备+外部备份 备份服务器为单独节点,归档日志从备节点复制

sys_rman工具的组件

sys_rman 在安装KingbaseES 数据库时已同步安装,但不能直接使用,需要进行相关初始化配置,以下是初始化配置相关组件。

1、sys_rman 备份的核心工具,可以在数据库或者备份节点执行,执行时,读取sys_rman.conf

2、sys_backup.sh 在备份节点上执行,执行初始化自动生成sys_rman.conf文件

3、sys_backup.conf 执行sys_backup.sh时需要读取该文件的配置信息

4、sys_rman.conf 由sys_backup.sh生成

下面介绍《单机+内部备份》配置过程

初始化配置

sys_backup.conf配置文件,需要调整备份IP,周期,数据库的连接信息等。

sys_backup.conf配置文件

[kingbase@dmdem bin]$ cat ../share/sys_backup.conf
#file: sys_backup.conf
#dest dir: <cluster_dir>/kingbase/bin/sys_backup.conf
#dest dir: <cluster_dir>/kingbase/share/sys_backup.conf

# target db style enum:  single/cluster/single-pro
_target_db_style="single"
# one kingbase node IP/hostname
# just provide one IP/hostname, script will use 'repmgr cluster show' get other node IP/hostname
_one_db_ip="192.168.20.253" 
# local repo IP/hostname, inner-REPO, means repo located in one db node
# outer repo IP/hostname, outer-REPO, means repo located in outer node
# support MULTI repo IP/hostname, separate by space, example: "10.10.10.11 10.10.10.12"
_repo_ip="192.168.20.253"
# label of this cluster
_stanza_name="kingbase"  
# OS user name of database 
_os_user_name="kingbase" 
# !!!! dir to store the backup files
# should be accessable for the OS user
_repo_path="/home/kingbase/backup/rmanbackup"
# count of keep, over the count FULL-backup will be remove
_repo_retention_full_count=3
# count of days, interval to do FULL-backup
_crond_full_days=7  
# count of days, interval to do DIFF-backup
_crond_diff_days=0 
# count of days, interval to do INCR-backup
_crond_incr_days=1
# HOUR to do the FULL-backup
_crond_full_hour=2 
# HOUR to do the DIFF-backup
_crond_diff_hour=3 
# HOUR to do the INCR-backup
_crond_incr_hour=4 
# band witdh limit, fixed in Mb/s, default 0 means no limit
_band_width=0
# OS cmd define
_os_ip_cmd="/sbin/ip"
_os_rm_cmd="/bin/rm"
_os_sed_cmd="/bin/sed"
_os_grep_cmd="/bin/grep"
_os_base64_cmd="/bin/base64"
# !!! these follow 4 parameter ONLY for single style
# data dir of single 
_single_data_dir="/opt/Kingbase/ES/V9/data"
# bin dir of single
_single_bin_dir="/opt/Kingbase/ES/V9/Server/bin"
# database user of single
_single_db_user="system"
# database port of single
_single_db_port="54321"

# on means sys_securecmd, off means normal ssh
_use_scmd=off

# whether to sys_start_backup() fastly, y or n
_start_fast=y
# whether to gz the target file,  none or gz
_compress_type=none
# if the non archived WAL files , more than this setting
# show ERROR and break the backup-init, fixed unit in MB, 128 ~ 1024
_non_archived_space=1024

# disable statistics of archived files or not, n or y
_archive_statistics=n

# Continue Incr-Backup
# y means Incr-Backup will merge current backup-set and it's reference into one new FULL backup-set
#   merge into FULL applied in crontab-job by _crond_full_days
#   normal Incr-Backup applied in crontab-job by _crond_incr_days
# n means no merge
_continue_incr=n

初始化

sys_backup.sh 进行初始化,其输出已经足够清晰,十分详细说明了操作的全过程。

[kingbase@dmdem bin]$ sh sys_backup.sh init       
# pre-condition: check the non-archived WAL files
# 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.


初始化之后,sys_rman会进行archive 日志备份

[kingbase@dmdem 12-1]$ ksql -Usystem kingbase
Type "help" for help.

kingbase=# show archive_command ;
                                                                      archive_command                                                                      
-----------------------------------------------------------------------------------------------------------------------------------------------------------
 export TZ=Asia/Shanghai;/opt/Kingbase/ES/V9/Server/bin/sys_rman --config /home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase archive-push %p
(1 row)

kingbase=#

备份任务的启停

启动

脚本使用crontab命令增加定时任务,使用sys_rman进行定时备份;可以通过crontab -l 查看定时任务。

[kingbase@dmdem bin]$ ./sys_backup.sh start
# pre-condition: check the non-archived WAL files
Enable some sys_rman in crontab-daemon
Set full-backup in 7 days
Set incr-backup in 1 days
0 2 * * * sh /opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/backup8.sh >>/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/logical_backup.log 2>&1 &
0 2 */7 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_incr.log 2>&1
[kingbase@dmdem bin]$ crontab -l          
0 2 * * * sh /opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/backup8.sh >>/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/logical_backup.log 2>&1 &
0 2 */7 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_incr.log 2>&1

停止

从系统CRONTAB中移除所有sys_rman相关的备份条目。

[kingbase@dmdem bin]$ ./sys_backup.sh stop
# pre-condition: check the non-archived WAL files
Disable all sys_rman in crontab-daemon
0 2 * * * sh /opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/backup8.sh >>/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/logical_backup.log 2>&1 &
[kingbase@dmdem bin]$ crontab -l          
0 2 * * * sh /opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/backup8.sh >>/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/logical_backup.log 2>&1 &

暂时停止定时备份

暂时停止定时备份动作。

[kingbase@dmdem bin]$ ./sys_backup.sh pause   
# pre-condition: check the non-archived WAL files
Pause the sys_rman...DONE
[kingbase@dmdem bin]$ crontab -l            
0 2 * * * sh /opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/backup8.sh >>/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/logical_backup.log 2>&1 &
0 2 */7 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_incr.log 2>&1

暂停备份,实际上是用sys_rman的stop命令,

## 部分代码
function func_pause()
{
	/bin/echo "Pause the sys_rman...DONE"
	${_rman_bin} --config=${_rman_conf_file} --stanza=${_stanza_name} stop >> ${_log_dir}/sys_rman_backup.log 2>&1
} # end of function pause

sys_rman的stop命令 实际上是在/tmp 目录创建了一个kingbase.stop标识,

注:使用系统strace命令可以跟踪sys_rman的执行,定位stop最后的执行

[kingbase@dmdem ~]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase stop                                    
2024-10-22 13:04:44.903 P00   INFO: stop command begin 2.27: --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=24442-e31ef0ca --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --stanza=kingbase
WARN: stop file already exists for stanza kingbase
2024-10-22 13:04:44.903 P00   INFO: stop command end: completed successfully (5ms)
[kingbase@dmdem ~]$ ll /tmp/sys_rman/kingbase.stop
-rw-r----- 1 kingbase kingbase 0 Oct 22 10:21 /tmp/sys_rman/kingbase.stop

恢复被暂停的定时备份

[kingbase@dmdem bin]$ ./sys_backup.sh unpause 
# pre-condition: check the non-archived WAL files
Un-Pause the sys_rman...DONE
[kingbase@dmdem bin]$ crontab -l              
0 2 * * * sh /opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/backup8.sh >>/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/SupTools/kb_backup/logical_backup.log 2>&1 &
0 2 */7 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /opt/Kingbase/ES/V9/Server/log/sys_rman_backup_incr.log 2>&1

恢复备份,实际上是用sys_rman的start命令,

function func_unpause()
{
	/bin/echo "Un-Pause the sys_rman...DONE"
	${_rman_bin} --config=${_rman_conf_file} --stanza=${_stanza_name} start >> ${_log_dir}/sys_rman_backup.log 2>&1
} # end of function unpause

sys_rman的start命令 实际上是删除/tmp 目录创建的一个kingbase.stop标识,

注:使用系统strace命令可以跟踪sys_rman的执行,定位start最后的执行

[kingbase@dmdem ~]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase start
2024-10-22 13:06:44.835 P00   INFO: start command begin 2.27: --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=24901-829dde33 --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --stanza=kingbase
2024-10-22 13:06:44.836 P00   INFO: start command end: completed successfully (5ms)
[kingbase@dmdem ~]$ ll /tmp/sys_rman/kingbase.stop
ls: cannot access /tmp/sys_rman/kingbase.stop: No such file or directory

sys_rman还原

完全还原恢复

停止数据库服务

[kingbase@dmdem kingbase]$ sys_ctl stop -D /opt/Kingbase/ES/V9/data
waiting for server to shut down.... done
server stopped

最新备份文件还原

$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --kb1-path=/opt/Kingbase/ES/V9/Server/datarestore --stanza=kingbase --archive-mode=off restore

-------------------PROCESS START-------------------
2024-10-22 14:15:49.616 P00   INFO: restore command begin 2.27: --archive-mode=off --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=8706-1b45a69a --kb1-path=/opt/Kingb
ase/ES/V9/Server/datarestore --link-all --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --non-archived-space=1024 --process-max=4 --repo1-pat
h=/home/kingbase/backup/rmanbackup --stanza=kingbase
2024-10-22 14:15:49.643 P00   INFO: repo1: restore backup set 20241022-135127F, recovery will start at 2024-10-22 13:51:27
2024-10-22 14:15:49.643 P00   INFO: remap data directory to '/opt/Kingbase/ES/V9/Server/datarestore'
2024-10-22 14:15:49.811 P00   INFO: Restore Process: FILE: 1 / 3330 0%       SZIE: 16777216 bytes / 1352487280 bytes 16MB / 1.3GB 1%
2024-10-22 14:15:49.812 P00   INFO: Restore Process: FILE: 2 / 3330 0%       SZIE: 33554432 bytes / 1352487280 bytes 32MB / 1.3GB 2%
.........
.........
2024-10-22 14:15:52.335 P00   INFO: Restore Process: FILE: 3327 / 3330 99%       SZIE: 1352487280 bytes / 1352487280 bytes 1.3GB / 1.3GB 100%
2024-10-22 14:15:52.636 P00   INFO: Restore Process: FILE: 3328 / 3330 99%       SZIE: 1352487280 bytes / 1352487280 bytes 1.3GB / 1.3GB 100%
2024-10-22 14:15:52.636 P00   INFO: Restore Process: FILE: 3329 / 3330 99%       SZIE: 1352487280 bytes / 1352487280 bytes 1.3GB / 1.3GB 100%
2024-10-22 14:15:52.636 P00   INFO: Restore Process: FILE: 3330 / 3330 100%       SZIE: 1352487280 bytes / 1352487280 bytes 1.3GB / 1.3GB 100%
2024-10-22 14:15:52.637 P00   INFO: write updated /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf
2024-10-22 14:15:52.639 P00   INFO: restore global/sys_control (performed last to ensure aborted restores cannot be started)
2024-10-22 14:15:52.639 P00   INFO: restore size = 1.3GB, file total = 3330
2024-10-22 14:15:52.640 P00   INFO: restore command end: completed successfully (3029ms)

还原后节点处理

[kingbase@dmdem kingbase]$ /opt/Kingbase/ES/V9/Server/bin/sys_ctl -D /opt/Kingbase/ES/V9/Server/datarestore start
waiting for server to start....2024-10-22 14:20:42.419 CST [9594] LOG:  sepapower extension initialized
2024-10-22 14:20:42.434 CST [9594] LOG:  starting KingbaseES V009R001C001B0030 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit
2024-10-22 14:20:42.434 CST [9594] LOG:  listening on IPv4 address "0.0.0.0", port 54321
2024-10-22 14:20:42.434 CST [9594] LOG:  listening on IPv6 address "::", port 54321
2024-10-22 14:20:42.435 CST [9594] LOG:  listening on Unix socket "/tmp/.s.KINGBASE.54321"
2024-10-22 14:20:42.510 CST [9594] LOG:  redirecting log output to logging collector process
2024-10-22 14:20:42.510 CST [9594] HINT:  Future log output will appear in directory "sys_log".
 done
server started

[kingbase@dmdem kingbase]$ k
Type "help" for help.

kingbase=# \l
                               List of databases
   Name    | Owner  | Encoding |   Collate   |    Ctype    | Access privileges 
-----------+--------+----------+-------------+-------------+-------------------
 db1       | system | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 kingbase  | system | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 security  | system | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | system | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/system        +
           |        |          |             |             | system=CTc/system
 template1 | system | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/system        +
           |        |          |             |             | system=CTc/system
 test      | system | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
(6 rows)

kingbase=# \c db1
You are now connected to database "db1" as userName "system".
db1=# \dt
              List of relations
 Schema |       Name        | Type  | Owner  
--------+-------------------+-------+--------
 public | create_table_test | table | system
 public | scan              | table | system
 public | t20241022         | table | system
 public | t20241023         | table | system
 public | t_sel             | table | system
(5 rows)

db1=# select count(1) from scan;
 count  
--------
 100000
(1 row)

清理kingbase.auto.conf文件内容

[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.

# Recovery settings generated by sys_rman restore on 2024-10-22 14:43:04
restore_command = '/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --kb1-path=/opt/Kingbase/ES/V9/Server/datarestore --stanza=kingbase archive-get %f "%p"'
recovery_target_time = '2024-10-22 14:33:00'
[kingbase@dmdem data]$ echo > /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf
[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf   

[kingbase@dmdem data]$ cat /dev/null > /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf   
[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf

不完全还原恢复

指定备份集、指定事务ID、指定时间点均属于PITR方式,上述方式还原后,需要谨慎地进行恢复。

停止数据库服务

[kingbase@dmdem kingbase]$ sys_ctl stop -D /opt/Kingbase/ES/V9/data
waiting for server to shut down.... done
server stopped

指定时间点还原

/opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --type=time --target='2024-10-22 14:33:00' --kb1-path=/opt/Kingbase/ES/V9/Server/datarestore restore

.....
2024-10-22 14:43:04.753 P00   INFO: Restore Process: FILE: 3332 / 3334 99%       SZIE: 1352759043 bytes / 1352759043 bytes 1.3GB / 1.3GB 100%
2024-10-22 14:43:04.953 P00   INFO: Restore Process: FILE: 3333 / 3334 99%       SZIE: 1352759043 bytes / 1352759043 bytes 1.3GB / 1.3GB 100%
2024-10-22 14:43:04.954 P00   INFO: Restore Process: FILE: 3334 / 3334 100%       SZIE: 1352759043 bytes / 1352759043 bytes 1.3GB / 1.3GB 100%
2024-10-22 14:43:04.954 P00   INFO: write updated /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf
2024-10-22 14:43:04.956 P00   INFO: restore global/sys_control (performed last to ensure aborted restores cannot be started)
2024-10-22 14:43:04.956 P00   INFO: restore size = 1.3GB, file total = 3334
2024-10-22 14:43:04.957 P00   INFO: restore command end: completed successfully (3061ms)

[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.

# Recovery settings generated by sys_rman restore on 2024-10-22 14:43:04
restore_command = '/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --kb1-path=/opt/Kingbase/ES/V9/Server/datarestore --stanza=kingbase archive-get %f "%p"'
recovery_target_time = '2024-10-22 14:33:00'   <=======

恢复

数据恢复过程,指的是经过还原动作后,新的数据库实例拥有了基本的数据文件,第一次启动数据库时,数据库根据恢复配置文件去拉取归档的WAL日志,进行REDO的过程。

恢复配置文件位于/kingbase.auto.conf,涉及恢复的部分主要包含以下配置项:

  • restore_command

配置为sys_rman工具archive-get命令,负责拉取归档的WAL日志,拉取的范围由后续参数确定。

如果没有recover_target_*相关选项,将自动拉取所有的归档WAL文件并执行REDO动作,将数据还原到最新的状态。

  • recovery_target_time

还原使用PITR功能–type=time时,填充相关值。

  • recovery_target_xid

还原使用PITR功能–type=xid时,填充相关值。

  • recovery_target_timeline

还原使用功能–target-timeline时,填充相关值。

  • recovery_target_action

还原使用功能–target-action时,填充相关值。

启动数据库

[kingbase@dmdem data]$ /opt/Kingbase/ES/V9/Server/bin/sys_ctl -D /opt/Kingbase/ES/V9/Server/datarestore start
waiting for server to start....2024-10-22 14:45:28.763 CST [14989] LOG:  sepapower extension initialized
2024-10-22 14:45:28.778 CST [14989] LOG:  starting KingbaseES V009R001C001B0030 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit
2024-10-22 14:45:28.778 CST [14989] LOG:  listening on IPv4 address "0.0.0.0", port 54321
2024-10-22 14:45:28.778 CST [14989] LOG:  listening on IPv6 address "::", port 54321
2024-10-22 14:45:28.779 CST [14989] LOG:  listening on Unix socket "/tmp/.s.KINGBASE.54321"
2024-10-22 14:45:28.852 CST [14989] LOG:  redirecting log output to logging collector process
2024-10-22 14:45:28.852 CST [14989] HINT:  Future log output will appear in directory "sys_log".
 done
server started

[kingbase@dmdem data]$ k
Type "help" for help.

kingbase=# select sys_is_wal_replay_paused() ;
 sys_is_wal_replay_paused 
--------------------------
 t
(1 row)

kingbase=# \c db1
You are now connected to database "db1" as userName "system".
db1=# \dt    
              List of relations
 Schema |       Name        | Type  | Owner  
--------+-------------------+-------+--------
 public | create_table_test | table | system
 public | scan              | table | system
 public | t20241022         | table | system
 public | t20241023         | table | system
 public | t20241024         | table | system
 public | t20241025         | table | system
 public | t_sel             | table | system
(7 rows)

db1=# create table t20241026 (id int);
ERROR:  cannot execute CREATE TABLE in a read-only transaction

db1=#  select sys_wal_replay_resume() ;   <============= 不完全恢复需要resume
 sys_wal_replay_resume 
-----------------------
 
(1 row)

db1=# select sys_is_wal_replay_paused() ;
ERROR:  recovery is not progressing
HINT:  The recovery-control-functions can only be executed during recovery.

db1=#  create table t20241026 (id int);
CREATE TABLE

清理kingbase.auto.conf文件内容

[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.

# Recovery settings generated by sys_rman restore on 2024-10-22 14:43:04
restore_command = '/opt/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --kb1-path=/opt/Kingbase/ES/V9/Server/datarestore --stanza=kingbase archive-get %f "%p"'
recovery_target_time = '2024-10-22 14:33:00'
[kingbase@dmdem data]$ echo > /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf
[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf   

[kingbase@dmdem data]$ cat /dev/null > /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf   
[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/datarestore/kingbase.auto.conf

常用管理命令

执行备份

注 : 执行备份后,会自动执行expire命令

全量

[kingbase@dmdem kingbase]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup

2024-10-18 16:31:15.245 P00   INFO: backup command begin 2.27: --archive-copy --no-archive-statistics --archive-timeout=600 --band-width=0 --compress-level=3 --compress-type=none --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=2483-e8c32f1c --kb1-path=/opt/Kingbase/ES/V9/data --kb1-port=54321 --kb1-user=system --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --non-archived-space=1024 --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --repo1-retention-full=3 --stanza=kingbase --start-fast --type=full
2024-10-18 16:31:15.272 P00   INFO: Get pageCheckSum flag from ControlFile is 0
2024-10-18 16:31:15.273 P00   INFO: Check the non archvied WAL space under the setting 1024 MB
2024-10-18 16:31:15.273 P00   INFO: Non archived WAL files have 0 MB.
..............                                    
.............. 
2024-10-22 13:51:32.349 P00   INFO: full backup size = 1.3GB, file total = 3330
2024-10-22 13:51:32.349 P00   INFO: backup command end: completed successfully (4484ms)
2024-10-22 13:51:32.350 P00   INFO: expire command begin 2.27: --archive-statistics --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=3428-79f485de --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --repo1-retention-full=3 --stanza=kingbase  <==============
2024-10-22 13:51:32.352 P00   INFO: repo1: 12-1 no archive to remove
2024-10-22 13:51:32.352 P00   INFO: expire command end: completed successfully (3ms)

增量

/opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup

2024-10-22 13:49:11.364 P00   INFO: backup command begin 2.27: --archive-copy --archive-statistics --archive-timeout=600 --band-width=0 --compress-level=3 --compress-type=none --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=2871-48f96abe --kb1-path=/opt/Kingbase/ES/V9/data --kb1-port=54321 --kb1-user=system --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --non-archived-space=1024 --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --repo1-retention-full=3 --stanza=kingbase --start-fast --type=incr
...........
...........
2024-10-22 13:49:12.543 P00   INFO: execute non-exclusive sys_stop_backup() and wait for all WAL segments to archive
2024-10-22 13:49:12.571 P00   INFO: backup stop archive = 000000010000000B000000BF, lsn = B/BF007668
2024-10-22 13:49:12.571 P00   INFO: check archive for segment(s) 000000010000000B000000BF:000000010000000B000000BF
2024-10-22 13:49:12.736 P00   INFO: new backup label = 20241022-020001F_20241022-134911I
2024-10-22 13:49:12.802 P00   INFO: incr backup size = 32.7MB, file total = 3329
2024-10-22 13:49:12.803 P00   INFO: backup command end: completed successfully (1444ms)
2024-10-22 13:49:12.803 P00   INFO: expire command begin 2.27: --archive-statistics --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=2871-48f96abe --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --repo1-retention-full=3 --stanza=kingbase   <================
2024-10-22 13:49:12.805 P00   INFO: expire command end: completed successfully (2ms)

查看备份集

[kingbase@dmdem kingbase]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase info
stanza: kingbase
    status: ok
    cipher: none

    db (current)
        wal archive min/max (V009R001C001B0030): 000000010000000B000000AF/000000010000000B000000BC

        full backup: 20241018-163115F
            timestamp start/stop: 2024-10-18 16:31:15 / 2024-10-18 16:31:19
            wal start/stop: 000000010000000000000039 / 00000001000000000000003A
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB

        full backup: 20241022-020001F
            timestamp start/stop: 2024-10-22 02:00:01 / 2024-10-22 02:00:05
            wal start/stop: 000000010000000B000000B3 / 000000010000000B000000B3
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB

        incr backup: 20241022-020001F_20241022-040001I
            timestamp start/stop: 2024-10-22 04:00:01 / 2024-10-22 04:00:03
            wal start/stop: 000000010000000B000000B5 / 000000010000000B000000B5
            database size: 1.3GB, database backup size: 20MB
            repo1: backup set size: 1.3GB, backup size: 20MB
            backup reference list: 20241022-020001F
# --type=basic 输出备份集和归档基本信息,sys_rman info 的默认行为
/opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase info --type=basic

# --type=archive 输出已归档文件的容量、起止时间和归档子目录等汇总信息
/opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase info --type=archive

切换归档
kingbase=# SELECT sys_switch_wal();

2024-10-22 14:32:00

# --type=disk 输出备份集和归档容量信息、占用磁盘空间百分比和磁盘剩余空间信息
/opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase info --type=disk

或者通过 sys_rman 插件做联机SQL查询获取这些信息。

create extension sys_rman;
select sys_rman.basic_info();
select sys_rman.archive_info();
select sys_rman.disk_info();

清理备份集

[kingbase@dmdem kingbase]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --set=20241022-020001F_20241022-094001I expire
2024-10-22 13:16:45.031 P00   INFO: expire command begin 2.27: --archive-statistics --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=27273-bf85c787 --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --repo1-retention-full=3 --set=20241022-020001F_20241022-094001I --stanza=kingbase
WARN: repo1: expiring latest backup 20241022-020001F_20241022-094001I - the ability to perform point-in-time-recovery (PITR) may be affected
      HINT: non-default settings for 'repo1-retention-archive'/'repo1-retention-archive-type' (even in prior expires) can cause gaps in the WAL.
2024-10-22 13:16:45.035 P00   INFO: repo1: expire adhoc backup 20241022-020001F_20241022-094001I
2024-10-22 13:16:45.036 P00   INFO: repo1: remove expired backup 20241022-020001F_20241022-094001I
2024-10-22 13:16:45.041 P00   INFO: expire command end: completed successfully (15ms)

备份集检查

[kingbase@dmdem kingbase]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase check
2024-10-22 13:24:37.996 P00   INFO: check command begin 2.27: --archive-timeout=600 --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=29159-444a86c3 --kb1-path=/opt/Kingbase/ES/V9/data --kb1-port=54321 --kb1-user=system --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --stanza=kingbase
2024-10-22 13:24:38.028 P00   INFO: check repo1 configuration (primary)
2024-10-22 13:24:38.038 P00   INFO: check repo1 archive for WAL (primary)
2024-10-22 13:24:38.140 P00   INFO: WAL segment 000000010000000B000000BD successfully archived to '/home/kingbase/backup/rmanbackup/archive/kingbase/12-1/000000010000000B/000000010000000B000000BD-4fb91c42ceab906a2c586196845f4c2763798b08' on repo1
2024-10-22 13:24:38.140 P00   INFO: check command end: completed successfully (152ms)
[kingbase@dmdem kingbase]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase verify
2024-10-22 13:25:07.078 P00   INFO: verify command begin 2.27: --archive-statistics --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=29280-62fb0dcb --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --non-archived-space=1024 --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --stanza=kingbase
2024-10-22 13:25:10.573 P00   INFO: Results:
                                      archive_id: 12-1, total WAL checked: 5, total valid WAL: 5
                                        missing: 0, checksum invalid: 0, size invalid: 0, other: 0
                                      backup: 20241018-163115F, status: valid, total files checked: 3323, total valid files: 3323
                                        missing: 0, checksum invalid: 0, size invalid: 0, other: 0
                                      backup: 20241022-020001F, status: valid, total files checked: 3328, total valid files: 3328
                                        missing: 0, checksum invalid: 0, size invalid: 0, other: 0
                                      backup: 20241022-020001F_20241022-040001I, status: valid, total files checked: 3329, total valid files: 3329
                                        missing: 0, checksum invalid: 0, size invalid: 0, other: 0
2024-10-22 13:25:10.573 P00   INFO: verify command end: completed successfully (3499ms)

合并备份集

可手动执行sys_rman的merge命令对备份集进行合并,减少存储空间的使用。

merge-no-delete,合并备份集,但不移除旧的备份集

merge-and-delete,合并备份集,移除旧的备份集

merge根据指定的增量备份集,合并此备份集、以及依赖的全量备份集、以及中间的依赖链条,形成一个新的全量备份集。

在执行文件级增量备份时,可选执行合并动作

一次合并2个增量备份,暂不清楚原理
/opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --set=20241022-020001F_20241022-134911I --merge_action=merge-and-delete merge

[root@dmdem log]# /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase info
stanza: kingbase
    status: ok
    cipher: none

    db (current)
        wal archive min/max (V009R001C001B0030): 000000010000000B000000AF/000000010000000B000000C1

        full backup: 20241018-163115F
            timestamp start/stop: 2024-10-18 16:31:15 / 2024-10-18 16:31:19
            wal start/stop: 000000010000000000000039 / 00000001000000000000003A
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB

        full backup: 20241022-020001F
            timestamp start/stop: 2024-10-22 02:00:01 / 2024-10-22 02:00:05
            wal start/stop: 000000010000000B000000B3 / 000000010000000B000000B3
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB

        incr backup: 20241022-020001F_20241022-040001I
            timestamp start/stop: 2024-10-22 04:00:01 / 2024-10-22 04:00:03
            wal start/stop: 000000010000000B000000B5 / 000000010000000B000000B5
            database size: 1.3GB, database backup size: 20MB
            repo1: backup set size: 1.3GB, backup size: 20MB
            backup reference list: 20241022-020001F

        incr backup: 20241022-020001F_20241022-134911I
            timestamp start/stop: 2024-10-22 13:49:11 / 2024-10-22 13:49:12
            wal start/stop: 000000010000000B000000BF / 000000010000000B000000BF
            database size: 1.3GB, database backup size: 32.7MB
            repo1: backup set size: 1.3GB, backup size: 32.7MB
            backup reference list: 20241022-020001F

        full backup: 20241022-135127F
            timestamp start/stop: 2024-10-22 13:51:27 / 2024-10-22 13:51:32
            wal start/stop: 000000010000000B000000C1 / 000000010000000B000000C1
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB
[root@dmdem log]# /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase --set=20241022-020001F_20241022-134911I --merge_action=merge-and-delete merge
2024-10-22 13:59:33.331 P00   INFO: merge command begin 2.27: --archive-statistics --compress-level=3 --compress-type=none --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=5372-db1c3bf0 --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --merge_action=merge-and-delete --repo1-path=/home/kingbase/backup/rmanbackup --repo1-retention-full=3 --set=20241022-020001F_20241022-134911I --stanza=kingbase
2024-10-22 13:59:33.333 P00   INFO: Will merge and delete
2024-10-22 13:59:33.490 P00   INFO: merge 20241022-020001F_20241022-134911I (reference 20241022-020001F) to 20241022-134911F
2024-10-22 13:59:33.608 P00   INFO: copied 3220 files from referenced backup set
2024-10-22 13:59:33.643 P00   INFO: finish mergence using 0
2024-10-22 13:59:33.645 P00   INFO: merge command end: completed successfully (319ms)
2024-10-22 13:59:33.645 P00   INFO: expire command begin 2.27: --archive-statistics --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=5372-db1c3bf0 --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --repo1-path=/home/kingbase/backup/rmanbackup --repo1-retention-full=3 --set=20241022-020001F --stanza=kingbase
2024-10-22 13:59:33.645 P00   INFO: expire the backup-set 20241022-020001F
2024-10-22 13:59:33.647 P00   INFO: repo1: expire adhoc backup set 20241022-020001F, 20241022-020001F_20241022-040001I, 20241022-020001F_20241022-134911I
2024-10-22 13:59:33.648 P00   INFO: repo1: remove expired backup 20241022-020001F_20241022-134911I
2024-10-22 13:59:33.655 P00   INFO: repo1: remove expired backup 20241022-020001F_20241022-040001I
2024-10-22 13:59:33.656 P00   INFO: repo1: remove expired backup 20241022-020001F
2024-10-22 13:59:33.693 P00   INFO: option 'repo-retention-archive' is not set - archive logs will not be expired
2024-10-22 13:59:33.693 P00   INFO: expire command end: completed successfully (48ms)
[root@dmdem log]# /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase info
stanza: kingbase
    status: ok
    cipher: none

    db (current)
        wal archive min/max (V009R001C001B0030): 000000010000000B000000AF/000000010000000B000000C1

        full backup: 20241018-163115F
            timestamp start/stop: 2024-10-18 16:31:15 / 2024-10-18 16:31:19
            wal start/stop: 000000010000000000000039 / 00000001000000000000003A
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB

        full backup: 20241022-134911F
            timestamp start/stop: 2024-10-22 13:49:11 / 2024-10-22 13:49:12
            wal start/stop: 000000010000000B000000BF / 000000010000000B000000BF
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB

        full backup: 20241022-135127F
            timestamp start/stop: 2024-10-22 13:51:27 / 2024-10-22 13:51:32
            wal start/stop: 000000010000000B000000C1 / 000000010000000B000000C1
            database size: 1.3GB, database backup size: 1.3GB
            repo1: backup set size: 1.3GB, backup size: 1.3GB

sys_rman.conf配置说明

运行时配置文件sys_rman.conf,不推荐手动修改,如果需要进行修改,请参考此段落:

以下参数修改后需要重新初始化生效

# DB节点的data目录
kb*-path=/home/kingbase/kingbase/data
# DB节点的监听端口
kb*-port=54321
# DB节点的数据库用户
kb*-user=esrep
# DB节点的IP地址
kb*-host=10.11.12.13
# DB节点的OS用户名
kb*-host-user=kingbase
# REPO节点的实际备份目录
repo1-path=/home/kingbase/kbbr_repo

修改完成后,执行以下命令完成重新初始化

/home/kingbase/cluster/project/cluster/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase stanza-create
/home/kingbase/cluster/project/cluster/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase check
/home/kingbase/cluster/project/cluster/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --type=full backup

以下参数修改后需要一次全量备份生效

# 是否压缩备份的数据,默认none不压缩,可选 none / gz
# 压缩将节约空间、消耗时间;不压缩将节约时间、消耗空间。
compress-type=none
# 压缩级别, 默认3, 1~9,9代表最大压缩,同时也最耗时
compress-level=3

修改完成后,执行以下命令完成一次全量备份:

/home/kingbase/cluster/project/cluster/kingbase/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --type=full backup

以下参数修改后直接生效

# REPO节点保留至多的全量备份
repo*-retention-full=5
# REPO节点的sys_rman工具日志保存路径
log-path=/home/kingbase/kingbase/log
# 写入到日志文件的日志级别, info debug trace
log-level-file=info
# 执行命令时屏幕的日志级别, info debug trace
log-level-console=info
# 是否记录子进程的日志, y / n
log-subprocess=y
# 多进程的至多数目
process-max=4
# 是否快速生成checkpoint,在开启实际备份之前
start-fast=y
# 是否保留目录下的软链接
link-all=y
# 未归档的WAL文件容量的警告阈值
non-archived-space=1024
# 归档单个WAL的超时时间
archive-timeout=600
# 限速,单位固定为MB/s
band-width=0
# 备份过程中遇到校验和等问题时会执行的自定义命令,如发送告警邮件等
alert-command=( cd /opt/Kingbase/ES/Server/bin; ./sys_mail -s "%t" -b "%c" & )

问题列表

初始化时,securecmdd 不工作

问题如下:

[kingbase@dmdem bin]$ ./sys_backup.sh init
ERROR: securecmdd does not work, please check

解决方法:

在配置文件中暂不使用

# 使用通讯协议,默认使用securecmdd,可选使用ssh
# on means securecmdd, off means normal ssh

[kingbase@dmdem backup]$ grep use_scmd /opt/Kingbase/ES/V9/Server/share/sys_backup.conf
_use_scmd=off

初始化时,repo-path 已存在

问题如下:

[kingbase@dmdem bin]$ sh sys_backup.sh init      
ERROR: Configured repo-path [/home/kingbase/backup/rmanbackup] already exists

解决方法:

删除rmanbackup目录,由程序自动生成。

初始化时,archive_command必须包含sys_rman

问题如下:

[kingbase@dmdem bin]$ sh sys_backup.sh init
# pre-condition: check the non-archived WAL files
# generate single sys_rman.conf...DONE
# update single archive_command with sys_rman.archive-push...DONE
# create stanza and check...(maybe 60+ seconds)
ERROR: check stanza failed, check log file /opt/Kingbase/ES/V9/Server/log/sys_rman_check.log

[kingbase@dmdem data]$ cat /opt/Kingbase/ES/V9/Server/log/sys_rman_check.log
2024-10-18 16:15:09.820 P00   INFO: check command begin 2.27: --archive-timeout=600 --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=30567-c127bc80 --kb1-path=/opt/Kingbase/ES/V9/data --kb1-port=54321 --kb1-user=system --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --stanza=kingbase
ERROR: [068]: archive_command ' cp %p /opt/Kingbase/ES/V9/data/archive/%f' must contain sys_rman
2024-10-18 16:15:09.844 P00   INFO: check command end: aborted with exception [068]
2024-10-18 16:26:52.495 P00   INFO: check command begin 2.27: --archive-timeout=600 --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=1103-ef429c99 --kb1-path=/opt/Kingbase/ES/V9/data --kb1-port=54321 --kb1-user=system --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --stanza=kingbase
ERROR: [068]: archive_command ' cp %p /opt/Kingbase/ES/V9/data/archive/%f' must contain sys_rman  <======
2024-10-18 16:26:52.526 P00   INFO: check command end: aborted with exception [068]

解决方法:

取消kingbase.conf 配置文件的archive_command 注释

[kingbase@dmdem data]$ grep archive_command kingbase.conf 
archive_command='export TZ=Asia/Shanghai;/opt/Kingbase/ES/V9/Server/bin/sys_rman --config /home/kingbase/backup/rmanbackup/sys_rman.conf --stanza=kingbase archive-push %p'

sys_rman还原 Permission denied

问题如下:

[kingbase@dmdem kingbase]$ /opt/Kingbase/ES/V9/Server/bin/sys_rman --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --kb1-path=/opt/Kingbase/ES/V9/Server/datarestore --stanza=kingbase --archive-mode=off restore
2024-10-22 14:12:19.291 P00   INFO: restore command begin 2.27: --archive-mode=off --band-width=0 --config=/home/kingbase/backup/rmanbackup/sys_rman.conf --exec-id=8070-99e44919 --kb1-path=/opt/Kingbase/ES/V9/Server/datarestore --link-all --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V9/Server/log --log-subprocess --non-archived-space=1024 --process-max=4 --repo1-path=/home/kingbase/backup/rmanbackup --stanza=kingbase
WARN: repo1: [file_open_err] unable to load info file '/home/kingbase/backup/rmanbackup/backup/kingbase/backup.info' or '/home/kingbase/backup/rmanbackup/backup/kingbase/backup.info.copy':
      file_open_err: unable to open file '/home/kingbase/backup/rmanbackup/backup/kingbase/backup.info' for read: [13] Permission denied
      file_open_err: unable to open file '/home/kingbase/backup/rmanbackup/backup/kingbase/backup.info.copy' for read: [13] Permission denied
      HINT: backup.info cannot be opened and is required to perform a backup.
      HINT: has a stanza-create been performed?
ERROR: [075]: no backup set found to restore
2024-10-22 14:12:19.293 P00   INFO: restore command end: aborted with exception [075]

解决方法:

查看对应文件权限,调整相应权限

[kingbase@dmdem kingbase]$ ll /home/kingbase/backup/rmanbackup/backup/kingbase/backup.info
-rw-r----- 1 root root 2378 Oct 22 13:59 /home/kingbase/backup/rmanbackup/backup/kingbase/backup.info

[root@dmdem kingbase]# ll
total 8
drwxrwxr-x 4 kingbase kingbase   42 Oct 18 16:31 backup
-rw-rw-r-- 1 kingbase kingbase 4542 Oct 16 13:32 recover_controlfile.py
[root@dmdem kingbase]# chown -R kingbase.kingbase backup

总结

sys_rman 工具功能比较完善,其初始化配置只需操作一次,后续备份命令与其他关系型数据库十分类似,这对于初学者相当友好,降低了学习成本,另外灵活的备份架构也给使用者更多的选择机会,也期待国产化发展越来越壮大。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论