KingbaseES R6 单节点数据库异机恢复案例
数据库运行硬件或系统环境如果发生了不可恢复的故障,这时只能采用异机恢复的方式恢复数据库。以下通过例子介绍异机恢复的过程。
一、硬件环境
192.168.237.101 | 数据库运行源主机 |
192.168.237.102 | 数据库恢复目标机(异机) |
192.168.237.103 | 数据库备份所在主机 REPO_DB |
二、初始化备份环境
在 103 主机配置 sys_backup.conf ,内容如下:
# target db style enum: single/cluster _target_db_style="single" # one kingbase node IP # just provide one IP, script will use 'repmgr cluster show' get other node IP _one_db_ip="192.168.237.101" # local repo IP, inner-REPO, must be same as one_db_ip, means repo located in one db node # outer repo IP, outer-REPO, means repo located in outer node _repo_ip="192.168.237.103" # label of this cluster _stanza_name="kingbase" # OS user name of database _os_user_name="c5" # !!!! dir to store the backup files # should be accessable for the OS user _repo_path="/home/c5/bak" # count of keep, over the count FULL-backup will be remove _repo_retention_full_count=5 # 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 # OS cmd define _os_ip_cmd="/sbin/ip" _os_rm_cmd="/bin/rm" _os_sed_cmd="/bin/sed" _os_grep_cmd="/bin/grep" # !!! these follow 4 parameter ONLY for single style # data dir of single _single_data_dir="/home/c5/ES/V8/data" # bin dir of single _single_bin_dir="/home/c5/ES/V8/Server/bin" # database user of single _single_db_user="system" # database port of single _single_db_port="54321"
运行 sys_backup.sh init , 验证数据库备份正常。
三、进行异机恢复
这里模拟101 环境宕机的情况。
1、ssh 互信配置
需要配置新的数据库主机 (102) 与备份主机 (103) 间的互信关系。因为数据库恢复时,需要从远程拷贝文件,需要配置相互间免密登录。
2、修改 REPO_IP 103 主机的 sys_rman.conf
[c5@nn03 bak]$ cat sys_rman.conf # Genarate by script at 20220114162108, should not change manually [kingbase] kb1-path=/home/c5/ES/V8/data --新数据库主机数据目录 kb1-port=54321 kb1-user=system kb1-host=192.168.237.102 --新数据库主机 kb1-host-user=c5 [global] repo1-path=/home/c5/bak repo1-retention-full=5 log-path=/home/c5/ES/V8/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
3、102 主机配置备份目录
创建目录:/home/c5/bak
创建 sys_rman.conf 文件
这个文件可以从原主机(101)拷贝,也可以从 备份主机拷贝,再进行修改
[c5@nn02 bak]$ cat sys_rman.conf # Genarate by script at 20220114162109, should not change manually [kingbase] kb1-path=/home/c5/ES/V8/data --目标数据库路径 [global] repo1-host=192.168.237.103 --REPO数据库所在主机 repo1-host-user=c5 repo1-host-config=/home/c5/bak/sys_rman.conf repo1-path=/home/c5/bak log-path=/home/c5/ES/V8/Server/log log-level-file=info log-level-console=info
4、在新数据库主机进行恢复
在102 主机进行恢复:
[c5@nn02 ~]$ sys_rman --config=/home/c5/bak/sys_rman.conf --stanza=kingbase --log-path=/tmp restore
5、验证恢复准确性
KINGBASE研究院