案例说明:

在生产环境通过sys_rman执行了物理备份后,需要在异机构建测试环境,本案例描述了通过物理备份异机恢复的详细过程及操作。

适用版本:

KingbaseES V8R3

节点信息:

[kingbase@node102 bin]$ cat /etc/hosts
......
192.168.1.101 node101 # 生产节点
192.168.1.102 node102 # 测试节点

一、生产库执行sys_rman物理备份

1、生产环境相关配置参数

# 开启归档
test=# show archive_mode ;
archive_mode
--------------
on
(1 row) # 归档文件存储路径
test=# show archive_dest ;
archive_dest
--------------------------
/data/kingbase/arch/c290
(1 row) # 归档配置
test=# show archive_command ;
archive_command
----------------------------------------------------------------------------
test ! -f /data/kingbase/arch/c290/%f && cp %p /data/kingbase/arch/c290/%f
(1 row) # wal日志配置
test=# show wal_level ;
wal_level
-----------
replica
(1 row)

2、执行sys_rman物理备份

1)备份初始化

[kingbase@node101 ~]$ mkdir -p /data/kingbase/bk/c290
[kingbase@node101 bin]$ ./sys_rman -U system -W 123456 -d test -D /opt/Kingbase/ES/C290/data -B /data/kingbase/bk/c290/ init

2)执行数据库全备

[kingbase@node101 bin]$ ./sys_rman -U system -W 123456 -d test -D /opt/Kingbase/ES/C290/data -B /data/kingbase/bk/c290/ -b full backup
INFO: validate: RTATKP backup and archive log files by CRC [kingbase@node101 bin]$ ./sys_rman -U system -W 123456 -d test -D /opt/Kingbase/ES/C290/data -B /data/kingbase/bk/c290/ validate
INFO: validate: RTATKP backup and archive log files by CRC
INFO: backup validation completed successfully

3)执行增量备份

# 事务操作
prod=# create table t2 as select * from t1;
SELECT 10000 prod=# select count(*) from t2;
count
-------
10000
(1 row) # 生成检查点(在恢复时,缩短recovery时间)。
prod=# select sys_switch_xlog();
sys_switch_xlog
-----------------
0/70000A0
(1 row) prod=# checkpoint;
CHECKPOINT # 执行正增量备份
[kingbase@node101 bin]$ ./sys_rman -U system -W 123456 -d test -D /opt/Kingbase/ES/C290/data -B /data/kingbase/bk/c290/ -b page backup
INFO: validate: RTATU1 backup and archive log files by CRC

4) 查看备份信息

[kingbase@node101 bin]$ ./sys_rman -U system -W 123456 -d test -D /opt/Kingbase/ES/C290/data -B /data/kingbase/bk/c290/ show
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RTATU1 2023-04-18 14:54:03 PAGE 1 / 0 2s 628kB 0/9000028 0/A000078 OK
RTATKP 2023-04-18 14:48:27 FULL 1 / 0 2s 80MB 0/3000028 0/3000130 OK

5)查看备份文件信息

[kingbase@node101 c290]$ ls -lh
total 4.0K
drwx------ 4 kingbase kingbase 32 Apr 18 14:54 backups
-rw-r--r-- 1 kingbase kingbase 41 Apr 18 14:47 sys_rman.conf
lrwxrwxrwx 1 kingbase kingbase 25 Apr 18 15:40 wal -> /data/kingbase/arch/c290/

二、sys_rman执行异机恢复

Tips:

物理备份的恢复一般分为两个步骤

restore: 还原备份数据文件到data目录下
reocovery: 启动实例后从最近的检查点开始应用xlog日志到一致性状态后,开启数据库。

1、准备数据库环境

  1)在测试主机安装和生产主机相同的数据库版本
2)创建相同的备份存储路径和xlog日志归档路径
3)归档及wal日志配置和生产库相同

2、复制生产库备份到测试主机

[kingbase@node101 c290]$ scp -r * node102:/data/kingbase/bk/c290/

3、执行sys_rman恢复

1)restore备份到data目录下

# 备份测试库data目录
[kingbase@node102 c290]$ cd /opt/Kingbase/ES/C290/
[kingbase@node102 C290]$ mv data data.bk # 创建data目录并授权
[kingbase@node102 bin]$ mkdir -p /opt/Kingbase/ES/C290/data
[kingbase@node102 bin]$ chmod 700 /opt/Kingbase/ES/C290/data # 在测试库上查看备份信息
[kingbase@node102 bin]$ ./sys_rman -U system -W 123456 -d test -D /opt/Kingbase/ES/C290/data -B /data/kingbase/bk/c290/ show
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RTATU1 2023-04-18 14:54:03 PAGE 1 / 0 2s 628kB 0/9000028 0/A000078 OK
RTATKP 2023-04-18 14:48:27 FULL 1 / 0 2s 80MB 0/3000028 0/3000130 OK # 执行sys_rman restore
[kingbase@node102 bin]$ ./sys_rman -U system -W 123456 -d test -D /opt/Kingbase/ES/C290/data -B /data/kingbase/bk/c290/ restore
INFO: validate: RTATKP backup and archive log files by SIZE
INFO: validate: RTATU1 backup and archive log files by SIZE
INFO: restore complete. Recovery starts automatically when the Kingbase server is started.

如下图所示,执行restore:

2)启动测试库实例执行recovery

# 启动数据库实例
[kingbase@node102 bin]$ ./sys_ctl start -D ../../data
server starting
....... # 查看sys_log日志
[kingbase@node102 sys_log]$ tail -1000 kingbase-2023-04-18_154713.log
2023-04-18 15:47:13 CST LOG: database system was interrupted; last known up at 2023-04-18 14:54:01 CST
2023-04-18 15:47:13 CST LOG: creating missing WAL directory "sys_xlog/archive_status"
2023-04-18 15:47:13 CST LOG: starting archive recovery
2023-04-18 15:47:13 CST LOG: restored log file "000000010000000000000009" from archive
2023-04-18 15:47:13 CST LOG: redo starts at 0/9000028
2023-04-18 15:47:13 CST LOG: redo wal segment count 1
2023-04-18 15:47:13 CST LOG: restored log file "00000001000000000000000A" from archive
2023-04-18 15:47:13 CST LOG: consistent recovery state reached at 0/A000078
2023-04-18 15:47:13 CST LOG: restored log file "00000001000000000000000B" from archive
2023-04-18 15:47:13 CST LOG: restored log file "00000001000000000000000C" from archive
cp: cannot stat ‘/data/kingbase/bk/c290//wal/00000001000000000000000D’: No such file or directory
2023-04-18 15:47:13 CST LOG: complete: 1/1
2023-04-18 15:47:13 CST LOG: redo done at 0/C0000D0
2023-04-18 15:47:13 CST LOG: last completed transaction was at log time 2023-04-18 14:54:03.704661+08
2023-04-18 15:47:13 CST LOG: restored log file "00000001000000000000000C" from archive
cp: cannot stat ‘/data/kingbase/bk/c290//wal/00000002.history’: No such file or directory
2023-04-18 15:47:13 CST LOG: selected new timeline ID: 2
2023-04-18 15:47:13 CST LOG: archive recovery complete
cp: cannot stat ‘/data/kingbase/bk/c290//wal/00000001.history’: No such file or directory
2023-04-18 15:47:13 CST LOG: MultiXact member wraparound protections are now enabled
2023-04-18 15:47:13 CST LOG: autovacuum launcher started
2023-04-18 15:47:13 CST LOG: database system is ready to accept connections
2023-04-18 15:47:13 CST LOG: starting syslogical supervisor
2023-04-18 15:47:13 CST LOG: starting syslogical database manager for database TEST
2023-04-18 15:47:13 CST LOG: manager worker [11755] at slot 0 generation 1 detaching cleanly
2023-04-18 15:47:13 CST LOG: starting syslogical database manager for database TEMPLATE1
2023-04-18 15:47:13 CST LOG: manager worker [11757] at slot 0 generation 2 detaching cleanly
2023-04-18 15:47:13 CST LOG: starting syslogical database manager for database TEMPLATE2
2023-04-18 15:47:13 CST LOG: manager worker [11758] at slot 0 generation 3 detaching cleanly
2023-04-18 15:47:13 CST LOG: starting syslogical database manager for database SAMPLES
2023-04-18 15:47:13 CST LOG: manager worker [11759] at slot 0 generation 4 detaching cleanly
2023-04-18 15:47:13 CST LOG: starting syslogical database manager for database SECURITY
2023-04-18 15:47:13 CST LOG: manager worker [11760] at slot 0 generation 5 detaching cleanly
2023-04-18 15:47:13 CST LOG: starting syslogical database manager for database prod
2023-04-18 15:47:13 CST LOG: manager worker [11761] at slot 0 generation 6 detaching cleanly

如下图所示,数据库执行reocvery操作:

三、测试库连接访问

[kingbase@node102 bin]$ ./ksql -U system -W 123456 test
ksql (V008R003C002B0290)
Type "help" for help. test=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+-------------+-------------+--------------------
prod | SYSTEM | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
SAMPLES | 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=CTcb/SYSTEM
TEMPLATE1 | SYSTEM | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/SYSTEM +
| | | | | SYSTEM=CTcb/SYSTEM
TEMPLATE2 | SYSTEM | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =Tc/SYSTEM +
| | | | | SYSTEM=CTcb/SYSTEM
TEST | SYSTEM | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
(7 rows) test=# \c prod
You are now connected to database "prod" as user "system".
prod=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------------------------+-------+--------
PUBLIC | pathman_cache_stats | view | SYSTEM
PUBLIC | pathman_concurrent_part_tasks | view | SYSTEM
PUBLIC | pathman_config | table | SYSTEM
PUBLIC | pathman_config_params | table | SYSTEM
PUBLIC | pathman_partition_list | view | SYSTEM
PUBLIC | t1 | table | SYSTEM
PUBLIC | t2 | table | SYSTEM
(7 rows) prod=# select count(*) from t1;
count
-------
10000
(1 row) prod=# select count(*) from t2;
count
-------
10000
(1 row) ---如上所示,测试库数据恢复到了最近的备份点。

三、总结

sys_rman物理备份支持异机恢复,操作过程相对比较简单;可以将生产库的备份目录建立nfs共享,然后在测试环境mount共享文件系统,不用再从生产主机将备份拷贝到测试主机。

KingbaseES V8R3 备份恢复案例 -- sys_rman物理备份异机恢复的更多相关文章

  1. KingbaseES R6 单节点数据库异机恢复案例

    数据库运行硬件或系统环境如果发生了不可恢复的故障,这时只能采用异机恢复的方式恢复数据库.以下通过例子介绍异机恢复的过程. 一.硬件环境 192.168.237.101 数据库运行源主机 192.168 ...

  2. rman恢复方案和oracle异机恢复

    这篇文章主要介绍了rman恢复方案和oracle异机恢复,需要的朋友可以参考下 注:①恢复的前提是已经做好备份②完全恢复数据库是数据库遇到故障,在恢复时候没有丢失任何已经提交事物数据的恢复不完全恢复数 ...

  3. RMAN - 备份异机恢复

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  4. RMAN 备份异机恢复 并创建新DBID

    测试平台信息: Oracle:11gR2 操作系统:Redhat 5.5 Target DB:dave   几点说明: (1)RMAN 异机恢复的时候,db_name必须相同. 如果说要想改成其他的实 ...

  5. RMAN备份策略与异机恢复一例(续篇)

    本文是<RMAN备份策略与异机恢复一例>的续篇,继续实验验证,最终实现两个需求: 1.异机恢复临时测试的小库 2.传输归档时,实现增量传输 1.异机恢复临时测试的小库 之前异机恢复的需求已 ...

  6. RMAN备份策略与异机恢复一例

    实验环境: A机器(生产用途):RHEL 6.5 + Oracle 11.2.0.4 + IP Address 192.168.1.11 B机器(备机用途):RHEL 6.5 + Oracle 11. ...

  7. rman备份与异机恢复

    一.rman备份脚本并为定时任务 #!/bin/bashsource ~/.bash_profileexport LANG=en_USBACKUP_DATE=`date +%d`#RMAN_LOG_F ...

  8. rman 备份并异机恢复

    1.RMAN 备份脚本 RUN { CONFIGURE RETENTION POLICY DAYS; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CO ...

  9. RMAN异机恢复遭遇ORA-01547、ORA-01152、ORA-01110错误案例

    测试环境:     操作系统  :  Red Hat Enterprise Linux ES release 4 (Nahant Update 4)   VMWARE     数据库     :  O ...

  10. ORACLE 异机恢复

    有时候需要将大的数据库发布到客户现场或转移机器时,不得不考虑在异机上恢复已经调整.测试好的库. dumpdp 全备的方法虽然易用,但在处理对象.索引.空间的时候异常的出错,比如:见有些公司,建表.索引 ...

随机推荐

  1. 解决putty连接报 connection refused

    Ubuntu中换个速度快点的源后 执行 $sudo apt-get install openssh-server 安装ssh协议 执行ifconfig显示Ubuntu的ip地址 xp中用putty输入 ...

  2. 利用nssm将jar包安装为windows服务

    1.介绍 假设我们有一个spring boot程序打包成jar文件放到windows服务器运行,第一种方式jar -jar xx方式在cmd运行.这样有个缺点,被别人误关闭了咋办?服务器重启了咋办? ...

  3. Java I/O 教程(六) BufferedInputStream 类

    Java BufferedInputStream Class Java BufferedInputStream class 用于从输入流读取数据,和BufferedOutStream一样内部使用缓冲机 ...

  4. Ansible的基本配置

    目录 定义主机和组 主机的定义 主机组的定于 主机组的嵌套 选择主机和组 匹配主机 使用通配符匹配 配置文件优先级 配置文件详解 配置文件段 配置文件参数说明 配置案例 1. 在节点上创建一个普通用户 ...

  5. java日期中YYYY与yyyy的区别

    date==>string string ==>date 总结: 个人觉得:当天所在的周属于的年份,一周从周日开始,周六结束,只要本周跨年,那么这周就算入下一年.这个结论在正向转换的时候是 ...

  6. 海康摄像SDK开发笔记(一):海康威视网络摄像头SDK介绍与模块功能

    前言   视频监控.人脸识别等应用中经常使用到摄像头,当前占据主流视频监控摄像头就是海康和大华两家,都可通过自家的sdk或者是onvif方式使用和控制摄像头.  本文章讲解海康的sdk方式.   海康 ...

  7. yolo7检测学习Bubbliiiing的视频有感——(1)no model named 'cv2'

    我一直以来也是喜欢用vscode,就跟随B导安装了vscode 下载完B导提供的代码后如果想直接跟着视频B导的操作运行predict.py文件是不可能的,需要按照readme文档中的所有提示按照步骤放 ...

  8. 【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name

    问题描述 Azure Web Job执行Powershell脚本报错 Select-AzContext : The term 'Select-AzContext' is not recognized ...

  9. 【Azure 应用服务】NodeJS项目部署在App Service For Linux环境中,部署完成后应用无法访问

    问题描述 NodeJS项目部署在App Service For Linux环境中,部署完成后应用无法访问,在启动日志中发现错误消息:ERROR - Container XXX_0 for site X ...

  10. 【Azure 应用服务】Azure Function 中运行Powershell 脚本,定位 -DefaultProfile 引发的错误

    问题描述 突然之间,使用PowerShell脚本 Get-AzVirtualNetwork 获取虚拟网络信息时,如果带上  -DefaultProfile $sub 参数,就出现 Azure cred ...