KingbaseES V8R6备份恢复案例--sys backup.sh start无法创建crontab任务

案例说明:
KingbaseES V8R6C5版本中使用了securecmdd工具,用于主机节点间的通讯。sys_backup.sh默认使用了securecmdd工具,对于通用机单实例环境,在执行“sys_backup.sh init”后,会调用securecmd工具连接主机节点备份,导致在执行“sys_backup.sh start”启动备份时,无法创建KINGBASECRON文件,建立cron计划任务,需要配置sys_backup.conf文件解决此问题。本案例是在通用机的单实例环境下测试。

适用版本:
KingbaseES V8R6

一、模拟生产生成测试数据

test=# create database prod;
CREATE DATABASE
test=# \c prod
   
prod=# create table t1(id int ,name varchar(10));
CREATE TABLE
prod=# insert into t1 values(generate_series(1,10000),'usr'||generate_series(1,10000));
INSERT 0 10000
prod=# select count(*) from t1;
 count
-------
 10000
(1 行记录)

二、备份前的配置
1、编辑sys_backup.conf文件

[kingbase@#localhost bin]$ cat sys_backup.conf |grep -v ^$|grep -v ^#
_target_db_style="single"
_one_db_ip="127.0.0.1"
_repo_ip="127.0.0.1"
_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
_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/Server/bin"
_single_db_user="system"
_single_db_port="54321"
_use_scmd=on

2、归档配置

[kingbase@#localhost data]$ cat kingbase.conf |grep -i archive_
archive_mode = on               # enables archiving; off, on, or always
archive_command='export TZ=Asia/Shanghai;/opt/Kingbase/ES/V8R6_054/Server/bin/sys_rman --config /home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase archive-push %p'
......

三、备份初始化(init)

Tips: 本案例服务器未启动securecmdd服务。

[kingbase@#localhost bin]$ ./sys_backup.sh init
Please input password ...
# 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.

备份配置文件:

[kingbase@#localhost kbbr_repo]$ cat sys_rman.conf
# Genarate by script at 20220420100146, should not change manually
[kingbase]
kb1-path=/data/kingbase/v8r6_054/data
kb1-port=54321
kb1-user=system

[global]
repo1-path=/home/kingbase/kbbr_repo
repo1-retention-full=5
log-path=/opt/Kingbase/ES/V8R6_054/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
cmd-ssh=/opt/Kingbase/ES/V8R6_054/Server/bin/sys_securecmd

四、启动备份创建cron任务

Tips:
默认在执行sys_backup.sh start后会在/etc/cron.d下创建KINGBASECRON的文件,用于启动备份的计划任务。

1、启动备份

[kingbase@#localhost bin]$ ./sys_backup.sh start
Enable some sys_rman in crontab-daemon
Set full-backup in 7 days
Set incr-backup in 1 days

2、查看生成的cron任务执行文件

[kingbase@#localhost bin]$ ls /etc/cron.d/ -lh
总用量 12K
-rw-r--r--. 1 root root 128 4月  11 2018 0hourly
-rw-r--r--. 1 root root 108 10月 30 2018 raid-check
-rw-------. 1 root root 235 10月 31 2018 sysstat

=== 如上所示,在指定目录下无KINGBASECRON文件生成===

五、问题处理

Tips:
系统需要建立kingbase和root用户之间的ssh信任关系。

1、配置sys_backup.conf文件

kingbase@#localhost bin]$ cat sys_backup.conf |grep use_
_use_scmd=off

---关闭securecmdd服务的调用,使用ssh建立到节点的连接。

2、重新执行备份初始化

[kingbase@#localhost bin]$ ./sys_backup.sh init
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:DZ21yge2aNDlVquhwFF4OWd36KwtdvmLYgrzwQILI5A.
ECDSA key fingerprint is MD5:f6:14:e3:de:0f:42:29:ed:1e:5f:66:d6:da:86:ed:ea.
Are you sure you want to continue connecting (yes/no)? yes
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:DZ21yge2aNDlVquhwFF4OWd36KwtdvmLYgrzwQILI5A.
ECDSA key fingerprint is MD5:f6:14:e3:de:0f:42:29:ed:1e:5f:66:d6:da:86:ed:ea.
Are you sure you want to continue connecting (yes/no)? yes
# 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、查看备份配置文件

[kingbase@#localhost kbbr_repo]$ cat sys_rman.conf
# Genarate by script at 20220420100618, should not change manually
[kingbase]
kb1-path=/data/kingbase/v8r6_054/data
kb1-port=54321
kb1-user=system

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

=== 如上所示,不再使用securecmdd作为节点间的通讯,直接使用ssh用于节点间通讯===

4、启动备份并创建cron任务

[kingbase@#localhost 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 /opt/Kingbase/ES/V8R6_054/Server/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /opt/Kingbase/ES/V8R6_054/Server/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * kingbase /opt/Kingbase/ES/V8R6_054/Server/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /opt/Kingbase/ES/V8R6_054/Server/log/sys_rman_backup_incr.log 2>&1

查看KINGBASECRON文件:
[kingbase@#localhost bin]$ cat /etc/cron.d/KINGBASECRON
0 2 */7 * * kingbase /opt/Kingbase/ES/V8R6_054/Server/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=full backup >> /opt/Kingbase/ES/V8R6_054/Server/log/sys_rman_backup_full.log 2>&1
0 4 */1 * * kingbase /opt/Kingbase/ES/V8R6_054/Server/bin/sys_rman --config=/home/kingbase/kbbr_repo/sys_rman.conf --stanza=kingbase --archive-copy --type=incr backup >> /opt/Kingbase/ES/V8R6_054/Server/log/sys_rman_backup_incr.log 2>&1

---如上所示,执行sys_backup.sh start后,成功建立备份的计划任务。

posted @ 2022-04-21 19:20  KINGBASE研究院  阅读(435)  评论(0编辑  收藏  举报