KingbaseES V8R6C5單例項sys_backup.sh備份案例
阿新 • • 發佈:2022-04-20
案例說明:
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)