客户有套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. Matlab Tricks(二十五)—— plot 属性

    marker: 边缘:'MarkerEdgeColor', [],(RGB 配色) 填充:'MarkerFaceColor', [](RGB 配色)

  2. 【u119】中位数

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], ...

  3. TensorFlow 学习(十二)—— 高级函数

    tf.map_fn(fn, elems):接受一个函数对象,然后用该函数对象对集合(elems)中的每一个元素分别处理, def preprocessing_image(image, training ...

  4. [GeekBand] C++继承关系下虚函数内存分布

    本文参考文献:GeekBand课堂内容,授课老师:侯捷 :深度探索C++对象模型(侯捷译) :网络资料,如:http://blog.csdn.net/sanfengshou/article/detai ...

  5. ajax——XMLHttpRequest

    XMLHttpRequest对象.能够让ajax程序在不又一次载入的页面的情况下更新页面数据,页面载入完毕后从server接受发生数据.这样既减轻了server负担又回顾了响应速度,缩短了用户的等待时 ...

  6. Android 对.properties文件的读取

    /** * * @param filepath .properties文件的位置 */ public void checkFileExists(String filepath){ File file ...

  7. IComparable与排序

    IComparable:一种特定于类型的通用比较方法,值类型或类通过实现此方法对特认定进行排序. IComparable的作用是提供了一种比较两个对象的特定类型的方法.这是必需的如果您想要为对象提供任 ...

  8. HSQL一个简短的引论

    前言     在对dao层写測试类的时候,我们须要一个測试数据库,一般我们会是专门建立一个真实的測试数据库,可是有了HSQLDB事情就变得简单了起来. 正题 一.简单介绍: hsql数据库是一款纯Ja ...

  9. “warning C4996: 'fopen': This function or variable may be unsafe”和“LINK : fatal error LNK1104”的解决办法

    程序有时编译出现警告C4996,报错:  warning C4996: 'fopen': This function or variable may be unsafe. Consider using ...

  10. OpenGL+VS2012编译环境配置

    OpenGL库主体分为三部分,分别是 gl(OpenGL核心库) glu(Utility Library,OpenGL实用库) glut(Utility Toolkit,OpenGL实用工具库) gl ...