C/C++教程

KingbaseES V8R6C5单实例sys_backup.sh备份案例

本文主要是介绍KingbaseES V8R6C5单实例sys_backup.sh备份案例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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

测试版本:

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 行记录)

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

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'
#archive_timeout = 0            # force a logfile segment switch after this
#archive_cleanup_command = ''   # command to execute at every restartpoint
#max_standby_archive_delay = 30s        # max delay before canceling queries

test=# show archive_command ;
                                                                     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
(1 行记录)

三、备份初始化(init)

[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任务
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文件生成===

五、问题处理
1、配置sys_backup.conf文件

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

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

# 查看cron任务
[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

5、查看备份信息

[kingbase@#localhost bin]$ ./sys_rman  --stanza=kingbase   --config=/home/kingbase/kbbr_repo/sys_rman.conf  info                         stanza: kingbase
    status: ok
    cipher: none

    db (current)
        wal archive min/max (V008R006C005B0054): 000000010000000000000004/000000010000000000000005

        full backup: 20220420-100622F
            timestamp start/stop: 2022-04-20 10:06:22 / 2022-04-20 10:06:25
            wal start/stop: 000000010000000000000005 / 000000010000000000000005
            database size: 78.3MB, database backup size: 78.3MB
            repo1: backup set size: 9MB, backup size: 9MB
            
[kingbase@#localhost bin]$ ./sys_rman  --stanza=kingbase   --config=/home/kingbase/kbbr_repo/sys_rman.conf  check
2022-04-20 10:17:43.328 P00   INFO: check command begin 2.27: --config=/home/kingbase/kbbr_repo/sys_rman.conf --exec-id=22425-af209cdf --kb1-path=/data/kingbase/v8r6_054/data --kb1-port=54321 --kb1-user=system --log-level-console=info --log-level-file=info --log-path=/opt/Kingbase/ES/V8R6_054/Server/log --log-subprocess --repo1-path=/home/kingbase/kbbr_repo --stanza=kingbase
2022-04-20 10:17:44.453 P00   INFO: check repo1 configuration (primary)
2022-04-20 10:17:44.958 P00   INFO: check repo1 archive for WAL (primary)
2022-04-20 10:17:45.059 P00   INFO: WAL segment 000000010000000000000006 successfully archived to '/home/kingbase/kbbr_repo/archive/kingbase/12-1/0000000100000000/000000010000000000000006-487da779cc4fcf6822f6d6c82116b1823700471e.gz' on repo1
2022-04-20 10:17:45.059 P00   INFO: check command end: completed successfully (1738ms)
这篇关于KingbaseES V8R6C5单实例sys_backup.sh备份案例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!