客户有套data guard环境,主库在阿里云上,备库在本地机房,现在想定期做备份,但是因为一些原因,备份阿里云上的主库实现会有些问题,所以只能备份本地的备库。目前需求就是测试备库的备份文件是否可以进行恢复,当误删除等操作之后,能否通过备份找回数据。以下为具体的测试:

1. 在data guard的备库进行完整+归档的备份

RMAN> run {
2> allocate channel t1 type disk;
3> allocate channel t2 type disk;
4> allocate channel t3 type disk;
5> allocate channel t4 type disk;
6> backup as compressed backupset INCREMENTAL LEVEL 0 FORMAT '/u01/app/oracle/racdb_data_%T_%s' database;
7> backup format '/u01/app/oracle/racdb_arch_%T_%s' skip inaccessible archivelog ALL not backed up;
8> backup format '/u01/app/oracle/racdb_cont_%T_%s' current controlfile;
9> release channel t1;
10> release channel t2;
11> release channel t3;
12> release channel t4;
13> }

2. 将文件拷贝到测试库上

[oracle@dg1 oracle]$ scp racdb_* 192.168.100.100:/u01/app/oracle/
oracle@192.168.100.100's password:
racdb_arch_20171018_24 100% 3646KB 3.6MB/s 00:00
racdb_arch_20171018_25 100% 30MB 30.1MB/s 00:01
racdb_arch_20171018_26 100% 2995KB 2.9MB/s 00:00
racdb_arch_20171018_27 100% 59MB 59.2MB/s 00:01
racdb_arch_20171018_28 100% 21MB 20.9MB/s 00:00
racdb_cont_20171018_29 100% 9856KB 9.6MB/s 00:00
racdb_data_20171018_19 100% 194MB 48.6MB/s 00:04
racdb_data_20171018_20 100% 77MB 77.0MB/s 00:01
racdb_data_20171018_21 100% 30MB 30.2MB/s 00:01
racdb_data_20171018_22 100% 1104KB 1.1MB/s 00:00
racdb_data_20171018_23 100% 96KB 96.0KB/s 00:00

3. 在主库上生成pfile文件,并拷贝到测试库上

SQL> create pfile='/home/oracle/pfileabbott' from spfile;

File created.

[oracle@dg1 ~]$ scp pfileabbott 192.168.100.100:/home/oracle
oracle@192.168.100.100's password:
pfileabbott 100% 1375 1.3KB/s 00:00

4. 在测试库上修改参数文件

[oracle@Abbott ~]$ mv pfileabbott $ORACLE_HOME/dbs/initabbott.ora
[oracle@Abbott ~]$ cd $ORACLE_HOME/dbs
[oracle@Abbott dbs]$ export ORACLE_SID=abbott
[oracle@Abbott dbs]$ vi initabbott.ora
*.audit_file_dest='/u01/app/oracle/admin/abbott/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/abbott/control01.ctl','/u01/app/oracle/fast_recovery_area/abbott/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='abbott'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=abbottXDB)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog'
*.log_archive_format='%t_%s_%r.arc'
*.log_archive_max_processes=30
*.open_cursors=300
*.pga_aggregate_target=655360000
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1967128576
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'

5. 测试库开启到nomount

[oracle@Abbott dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 17 08:24:18 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started. Total System Global Area 1970864128 bytes
Fixed Size 2254544 bytes
Variable Size 520096048 bytes
Database Buffers 1442840576 bytes
Redo Buffers 5672960 bytes
SQL>

6. 恢复控制文件

[oracle@Abbott ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Oct 17 09:29:20 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ABBOTT (not mounted)

RMAN> restore controlfile from '/u01/app/oracle/racdb_cont_20171018_29';

Starting restore at 17-OCT-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/abbott/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/abbott/control02.ctl
Finished restore at 17-OCT-17 RMAN> alter database mount; database mounted
released channel: ORA_DISK_1

7. 恢复数据文件

RMAN> restore database;

Starting restore at 17-OCT-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=150 device type=DISK channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/abbott/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/abbott/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_21
channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_21 tag=TAG20171018T153509
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/abbott/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/abbott/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_20
channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_20 tag=TAG20171018T153509
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/abbott/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_19
channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_19 tag=TAG20171018T153509
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 17-OCT-17

8. 恢复数据库

RMAN> recover database;

Starting recover at 17-OCT-17
using channel ORA_DISK_1 starting media recovery channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=196
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_arch_20171018_28
channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_arch_20171018_28 tag=TAG20171018T153550
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/archivelog1_196_953375126.arc thread=1 sequence=196
unable to find archived log
archived log thread=1 sequence=197
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/17/2017 09:33:30
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 197 and starting SCN of 1907246

9. 将数据库open

RMAN> alter database open;

database opened

RMAN> quit

Recovery Manager complete.

10. 连接数据库后,无法创建表等,因为控制文件是standby controlfile,所以打开的模式为READ ONLY

[oracle@Abbott ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 17 09:41:46 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> create table t1(a int);
create table t1(a int)
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-16000: database open for read-only access SQL> select open_mode , database_role, flashback_on from v$database; OPEN_MODE DATABASE_ROLE FLASHBACK_ON
-------------------- ---------------- ------------------
READ ONLY PHYSICAL STANDBY NO

11. 尝试启用备库,因缺少standby log报错

SQL> alter database activate standby database;
alter database activate standby database
*
ERROR at line 1:
ORA-00314: log 4 of thread 1, expected sequence# 197 doesn't match 0
ORA-00312: online log 4 thread 1: '/u01/app/oracle/oradata/abbott/std_log4.log' SQL> select * from v$standby_log;
select * from v$standby_log
*
ERROR at line 1:
ORA-00339: archived log does not contain any redo
ORA-00334: archived log: '/u01/app/oracle/oradata/abbott/std_log4.log'

12. 因此对缺少的log进行clear及drop(当然,这里也可以把standby redo拷贝过来,并进行open)

SQL> alter database drop logfile group 4;
alter database drop logfile group 4
*
ERROR at line 1:
ORA-00314: log 4 of thread 1, expected sequence# 197 doesn't match 0
ORA-00312: online log 4 thread 1: '/u01/app/oracle/oradata/abbott/std_log4.log' SQL> ALTER DATABASE CLEAR LOGFILE GROUP 4; Database altered. SQL> alter database drop logfile group 4; Database altered.

13. 再次arctive备库,启动正常,并且open之后可读写

SQL> alter database activate standby database;   

Database altered.

SQL> select open_mode , database_role, flashback_on from v$database;

OPEN_MODE            DATABASE_ROLE    FLASHBACK_ON
-------------------- ---------------- ------------------
MOUNTED PRIMARY NO SQL> alter database open; Database altered. SQL> select open_mode , database_role, flashback_on from v$database; OPEN_MODE DATABASE_ROLE FLASHBACK_ON
-------------------- ---------------- ------------------
READ WRITE PRIMARY NO SQL> create table t1(a int); Table created. SQL>
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archivelog
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
SQL>

oracle data guard备库备份恢复的更多相关文章

  1. ORACLE 11g 用Duplicate恢复Data Guard 备库详细过程

    1.先查找备库控制文件路径 先在备库上找出控制文件的路径,通过和主库一样,不过为了以防万一,还是check为好. SQL>  select name from v$controlfile; NA ...

  2. Oracle 12c DG备库Alert报错ORA-01110

    环境是12.2.0.1 version, Oracle Data Guard备库近段时间一直报错,但是备库主库同步一致,数据一致. 2019-03-06T23:42:22.184048+08:00 E ...

  3. Oracle Data Guard

    DG 是 Oracle Data Guard 的简称.也就是Oracle11g的 数据卫士. 由于在工作中 Oracle和 SQL SERVER2008 同时都需要维护管理.给我的感觉这里的 DG 其 ...

  4. (转)Oracle Data Guard学习

    一.Data Guard提供如下三种数据保护模式: 1)最高保护模式(Maximum Protection) 这里的”最高保护“是指最大限度的保护数据不丢失,也就是至少有一个standby和prima ...

  5. Oracle Data Guard配置

    Oracle Data Guard 的配置在网上有很多资料,但是没有一个完整的,配置下来多少有些问题.在踩了各种坑之后,自己终于配置成功,就想把这过程记录下来. 1   测试环境 主数据库:windo ...

  6. Oracle Data Guard 重要配置参数

    Oracle Data Guard主要是通过为生产数据库提供一个或多个备用数据库(是产生数据库的一个副本),以保证在主库不可用或异常时数据不丢失并通过备用数据库继续提供服务.对于Oracle DG的配 ...

  7. Oracle data guard学习

    Oracle data guard学习:三思笔记 Data guard 1data guard结构: data guard是一个集合,由一个primary数据库(生产数据库)和一个或多个standby ...

  8. Oracle Data Guard的配置

    概述 Oracle Data Guard 是针对企业数据库的最有效和最全面的数据可用性.数据保护和灾难恢复解决方案.它提供管理.监视和自动化软件基础架构来创建和维护一个或多个同步备用数据库,从而保护数 ...

  9. Oracle data guard 10g 搭建

    Oracle data guard 10g 搭建 1系统常规参数检查 硬盘 [root@localhost ~]# df -h 内核 [root@localhost ~]# uname -a [roo ...

随机推荐

  1. 【hdu 2897】邂逅明下

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  2. C语言编写静态链接库及其使用

    本篇讲述使用C语言编写静态链接库,而且使用C和C++的方式来调用等. 一.静态库程序:执行时不独立存在,链接到可执行文件或者动态库中,目标程序的归档. 1.用C编写静态库步骤 a.建立项目(Win32 ...

  3. Sqlplus的一般操作

    Sqlplus一些必要操作指令 1, 登陆sys 用户,需要加上 as sysdba Connect sys as sysdba; Input your password; Connected; 2, ...

  4. hello.c内核模块编译 -- linux内核

    Linux开发模块,在本机上看调试信息的方法走通了.当前版本号2.6.32-32-generic uname –r 能够查询 这里取module_param()作为样例. 该宏被定义在include/ ...

  5. TEdit,TMemo背景透明(SetWindowLong(WS_EX_TRANSPARENT)增加透明风格)

    The component below works perfectly, except for the following problem: 1) Saves the component below ...

  6. 【37.00%】【vijos p1425】子串清除

    P1425子串清除Accepted 标签:[显示标签] 描述 我们定义字符串A是字符串B的子串当且仅当我们能在B串中找到A串.现在给你一个字符串A,和另外一个字符串B,要你每次从B串中从左至右找第一个 ...

  7. JAVA从本机获取IP地址

    JAVA从本机获取IP地址 论述: 此篇博客是在工作的时候,需要获得当前网络下面正确的ip地址,在网上查阅很多博客,网上一个比较普遍的说法是通过InetAddress.getLocalHost().g ...

  8. struts2和velocity整合问题

    以下是我第一次使用velocity的时候写的 2012-03-12 话说struts真够懒的,都把velocity-1.6.4.jar放到他自己的lib里边了,就不给放全了,搞得新手太郁闷了.stru ...

  9. C# 8.0 预览特性

    初试C# 8.0 Visual Studio 2019的第一个预览版(使用Visual Studio 2019提高每个开发人员的工作效率)和.NET Core 3.0(宣布.NET Core 3预览1 ...

  10. win7 UAC bypass(微软已经给予了三组组件绕过UAC启动的特权)

    fireworm同学的翻译: 原文在http://www.pretentiousname.com/misc/win7_uac_whitelist2.html我只翻译了其中关于原理的一小部分,有兴趣的可 ...