如何用Dummy实例执行数据库的还原和恢复
今天实验了一下,如何在所有文件,包括数据文件,在线日志文件,控制文件都丢失的情况下,利用RMAN备份恢复和还原数据库。该实验的重点是用到了Dummy实例。
具体步骤如下:
备份数据库
[oracle@node2 ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Mon May 25 23:25:51 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: TEST (DBID=2176055307) RMAN> backup database; Starting backup at 25-MAY-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/test/users02.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/test/undotbs02.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAY-15
channel ORA_DISK_1: finished piece 1 at 25-MAY-15
piece handle=/u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_nnndf_TAG20150525T232624_bp6hs0oo_.bkp tag=TAG20150525T232624 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:01
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 25-MAY-15
channel ORA_DISK_1: finished piece 1 at 25-MAY-15
piece handle=/u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_ncsnf_TAG20150525T232624_bp6hx32w_.bkp tag=TAG20150525T232624 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
Finished backup at 25-MAY-15 RMAN> quit
模拟数据丢失
[oracle@node2 ~]$ cd /u01/app/oracle/oradata/test
[oracle@node2 test]$ ls
control01.ctl redo01.log redo03.log sysaux01.dbf temp01.dbf undotbs02.dbf users02.dbf
control01.dbf redo02.log redo04.log system01.dbf undotbs01.dbf users01.dbf
[oracle@node2 test]$ rm ./*
试着登录数据库查询数据,会报以下错误:
[oracle@node2 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Mon May 25 23:35:49 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected.
SQL> select * from scott.dept;
select * from scott.dept
*
ERROR at line 1:
ORA-01012: not logged on
Process ID: 0
Session ID: 0 Serial number: 0
看看ORACLE相关进程,会发现实例并没有奔溃,进程还在
[oracle@node2 ~]$ ps -ef |grep ora
root 1362 1320 0 19:25 ? 00:00:08 hald-addon-storage: polling /dev/sr0 (every 2 sec)
root 2809 1384 0 22:22 ? 00:00:00 sshd: oracle [priv]
oracle 2811 2809 0 22:22 ? 00:00:01 sshd: oracle@pts/7
oracle 2812 2811 0 22:22 pts/7 00:00:00 -bash
root 3006 1384 0 22:31 ? 00:00:00 sshd: oracle [priv]
oracle 3008 3006 0 22:31 ? 00:00:00 sshd: oracle@pts/1
oracle 3009 3008 0 22:31 pts/1 00:00:00 -bash
root 3120 1384 0 22:34 ? 00:00:00 sshd: oracle [priv]
oracle 3122 3120 0 22:34 ? 00:00:00 sshd: oracle@pts/8
oracle 3123 3122 0 22:34 pts/8 00:00:00 -bash
root 3482 1384 0 22:57 ? 00:00:00 sshd: oracle [priv]
oracle 3484 3482 0 22:57 ? 00:00:01 sshd: oracle@pts/3
oracle 3485 3484 0 22:57 pts/3 00:00:00 -bash
root 3566 1384 0 23:01 ? 00:00:00 sshd: oracle [priv]
oracle 3568 3566 0 23:01 ? 00:00:00 sshd: oracle@pts/9
oracle 3569 3568 0 23:01 pts/9 00:00:00 -bash
oracle 4035 1 0 23:23 ? 00:00:00 ora_pmon_test
oracle 4037 1 0 23:23 ? 00:00:00 ora_psp0_test
oracle 4039 1 4 23:23 ? 00:00:32 ora_vktm_test
oracle 4043 1 0 23:23 ? 00:00:00 ora_gen0_test
oracle 4045 1 0 23:23 ? 00:00:00 ora_diag_test
oracle 4047 1 0 23:23 ? 00:00:00 ora_dbrm_test
oracle 4049 1 0 23:23 ? 00:00:00 ora_dia0_test
oracle 4051 1 0 23:23 ? 00:00:00 ora_mman_test
oracle 4053 1 0 23:23 ? 00:00:00 ora_dbw0_test
oracle 4055 1 0 23:23 ? 00:00:00 ora_lgwr_test
oracle 4057 1 0 23:23 ? 00:00:00 ora_ckpt_test
oracle 4059 1 0 23:23 ? 00:00:00 ora_smon_test
oracle 4061 1 0 23:23 ? 00:00:00 ora_reco_test
oracle 4063 1 0 23:23 ? 00:00:02 ora_mmon_test
oracle 4065 1 0 23:23 ? 00:00:00 ora_mmnl_test
oracle 4067 1 0 23:23 ? 00:00:00 ora_d000_test
oracle 4069 1 0 23:23 ? 00:00:00 ora_s000_test
oracle 4081 1 0 23:23 ? 00:00:00 ora_arc0_test
oracle 4083 1 0 23:23 ? 00:00:00 ora_arc1_test
oracle 4085 1 0 23:23 ? 00:00:00 ora_arc2_test
oracle 4087 1 0 23:23 ? 00:00:00 ora_arc3_test
oracle 4089 1 0 23:23 ? 00:00:00 ora_qmnc_test
oracle 4103 1 0 23:24 ? 00:00:01 ora_cjq0_test
oracle 4105 1 0 23:24 ? 00:00:00 ora_q000_test
oracle 4107 1 0 23:24 ? 00:00:00 ora_q001_test
oracle 4109 1 0 23:24 ? 00:00:05 ora_vkrm_test
oracle 4129 1 0 23:24 ? 00:00:00 ora_smco_test
oracle 4131 1 0 23:24 ? 00:00:00 ora_w000_test
oracle 4149 1 0 23:29 ? 00:00:00 ora_w001_test
oracle 4151 1 0 23:29 ? 00:00:00 ora_w002_test
oracle 4153 1 0 23:30 ? 00:00:00 ora_w003_test
oracle 4178 3123 0 23:35 pts/8 00:00:00 sqlplus as sysdba
oracle 4186 4178 0 23:36 ? 00:00:00 oracletest (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 4187 3485 0 23:36 pts/3 00:00:00 ps -ef
oracle 4188 3485 0 23:36 pts/3 00:00:00 grep ora
关闭数据库
SQL> shutdown abort
ORACLE instance shut down.
现在开始恢复数据库,在这里会借助Oracle的dummy实例,即哑实例。
[oracle@node2 ~]$ export ORACLE_SID=dummy
[oracle@node2 ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Mon May 25 23:44:28 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) RMAN> startup nomount startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0.1/db_1/dbs/initdummy.ora' starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started Total System Global Area 1071333376 bytes Fixed Size 1369420 bytes
Variable Size 281021108 bytes
Database Buffers 784334848 bytes
Redo Buffers 4608000 bytes RMAN> restore spfile to '/u01/app/oracle/product/11.2.0.1/db_1/dbs/spfiletest.ora' from '/u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_ncsnf_TAG20150525T232624_bp6hx32w_.bkp'; Starting restore at 25-MAY-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=171 device type=DISK channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_ncsnf_TAG20150525T232624_bp6hx32w_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 25-MAY-15 RMAN> shutdown immediate Oracle instance shut down
在这里,我们将spfile恢复到实例默认的目录,即$ORACLE_HOME/dbs,采用的是默认值,即spfile实例名.ora。这样,在将数据库启动到nomount状态下,直接startup nomount即可。
恢复控制文件
[oracle@node2 ~]$ export ORACLE_SID=test
[oracle@node2 ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Mon May 25 23:54:50 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) RMAN> startup nomount Oracle instance started Total System Global Area 313860096 bytes Fixed Size 1364340 bytes
Variable Size 268439180 bytes
Database Buffers 37748736 bytes
Redo Buffers 6307840 bytes RMAN> restore controlfile from '/u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_ncsnf_TAG20150525T232624_bp6hx32w_.bkp'; Starting restore at 26-MAY-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=136 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/test/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/test/control02.ctl
Finished restore at 26-MAY-15
注意,要重新设置ORACLE_SID的值,不然启动的依旧是dummy实例。
将数据库启动到mount阶段
RMAN> alter database mount; database mounted
released channel: ORA_DISK_1
还原和恢复数据库
RMAN> restore database; Starting restore at 26-MAY-15
Starting implicit crosscheck backup at 26-MAY-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=136 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 26-MAY-15 Starting implicit crosscheck copy at 26-MAY-15
using channel ORA_DISK_1
Finished implicit crosscheck copy at 26-MAY-15 searching for all files in the recovery area
cataloging files...
cataloging done List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_ncsnf_TAG20150525T232624_bp6hx32w_.bkp using channel ORA_DISK_1 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/test/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/test/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/test/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/test/users02.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/test/undotbs02.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_nnndf_TAG20150525T232624_bp6hs0oo_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TEST/backupset/2015_05_25/o1_mf_nnndf_TAG20150525T232624_bp6hs0oo_.bkp tag=TAG20150525T232624
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:06
Finished restore at 26-MAY-15 RMAN> recover database; Starting recover at 26-MAY-15
using channel ORA_DISK_1 starting media recovery unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/26/2015 00:19:20
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 956515 RMAN> alter database open resetlogs; database opened
至此,数据库恢复完毕,该恢复属于不完全恢复,毕竟,在线日志文件在“模拟数据丢失”那一步已被删除,完全恢复已不可能,同时,上述倒数第二步recover database提示所需的归档文件不存在,指的也是已被删除的在线日志文件。在这里,直接resetlogs即可。
总结:
1> 如果启用了RMAN的自动备份功能configure autobackup on,在恢复spfile和controlfile那一步可直接执行restore spfile from autobackup和restore controlfile from autobackup,不用上述那么麻烦,需要指定备份集。当然,在这种情况下,需指定dbid。
2> OCP官方教材里面其实也提供了在一切都丢失的情况下,如何执行数据库的还原和恢复的脚本,具体如下:
RMAN> run{startup nomount pfile=dummy.pfile;
2> set dbid=2176055307;
3> restore spfile from autobackup;
4> shutdown abort;
5> startup nomount;
6> restore controlfile from autobackup;
7> alter database mount;
8> restore database;
9> recover database;
10> alter database open resetlog;}
关于这个脚本,说明如下:
第1行,使用只有一个参数(DB_NAME)的哑参数文件启动实例
第2行,告诉RMAN所使用的数据库的DBID
第3行,根据默认目录和默认值,从最近的自动备份集中提取spfile
第4行,关闭哑实例
第5行,利用还原的spfile启动实例
第6行,从最近的备份集中提取控制文件
第7行,加载控制文件
第8行,还原所有数据文件
第9行,通过应用增量备份以及归档日志文件和联机日志文件执行完整恢复。
第10行,打开数据库并重新初始化在线重做日志文件,在还原控制文件后总是需要resetlogs。
如何用Dummy实例执行数据库的还原和恢复的更多相关文章
- DM8数据库备份还原的原理及应用
(本文部分内容摘自DM产品技术支持培训文档,如需要更详细的文档,请查询官方操作手册,谢谢) 一.原理 1.DM8备份还原简介 1.1.基本概念 (1)表空间与数据文件 ▷ DM8表空间类型: ▷ SY ...
- 《SQL Server企业级平台管理实践》读书笔记——关于SQL Server数据库的还原方式
本篇是继上篇的备份方式,本篇介绍的是还原方案,在SQL Server在2005以上现有的还原方案一般分为以下4个级别的数据还原: 1.数据库完整还原级别: 还原和恢复整个数据库.数据库在还原和恢复操作 ...
- 用asp.net还原与恢复sqlserver数据库
上次做了个项目,涉及到数据库的还原和恢复,到网上找了一下,是利用SQLDMO实现的,只要添加SQLDMO引用就好了,然后利用下边的类的方法就可以实现了. 我把原作者的类扩充了一下,可以自动识别web. ...
- PHP执行数据库定时备份 和手动还原
一 备份数据库 我的这个是在TP5上,其实不在TP5也可以 逻辑: 1 首先在自己电脑的cmd命令上测试备份数据库,成功才能往下进行所以得到 C:/luanxiede/mysql-5.7/bin/my ...
- SQL Server 2008 数据库镜像部署实例之一 数据库准备
SQL Server 2008 数据库镜像部署实例之一 数据库准备 一.目标 利用Sql Server 2008 enterprise X64,建立异步(高性能)镜像数据库,同时建立见证服务器实现自动 ...
- SqlServer nvarchar中的中文字符匹配,更改SqlServer实例和数据库排序规则的办法
我们都知道在SqlServer中的nvarchar类型可以完美的存储诸如中文这种unicode字符,但是我们会发现有时候查询语句去查询nvarchar列的时候查不出来. 为什么nvarchar类型有时 ...
- MySQL数据库备份还原(基于binlog的增量备份)
MySQL数据库备份还原(基于binlog的增量备份) 一.简介 1.增量备份 增量备份 是指在一次全备份或上一次增量备份后,以后每次的备份只需备份与前一次相比增加或者被修改的文件.这就意味 ...
- (Les16 执行数据库恢复)-表空间恢复
NOARCHIVELOG模式下丢失了数据文件 数据库处于NOARCHIVELOG模式时,如果丢失任何数据文件,执行以下步骤 1.如果实例尚未关闭,请关闭实例 2 ...
- QunInfo群数据库的还原与优化
一. 背景 这个数据库的数据文件mdf大概有8.5G左右,当还原数据库之后感觉可以做很多性能方面上的调优,合并数据后mdf数据文件大概有6.2G左右,行压缩后mdf数据文件大概有4.8G左右,页压缩后 ...
随机推荐
- centos7 时间设置
安装完成centos7后,虽然时区选择的是上海,但是最终的时间还是不对,因为没有开启自动同步NTP功能,所以需要自动手动设置. 首先输入timedatectl命令,查看当前机器的时间: Local t ...
- CI生成查询记录集result(),row(),row_array().....
result() 该方法执行成功返回一个对象数组,失败则返回一个空数组. 一般情况下,我们使用下面的方法遍历结果,代码就像这样: $query = $this->db->query(&qu ...
- python 函数之day3
一 函数的语法及特性 什么是函数? 定义:函数是一个功能通过一组语句的集合,由名字(函数名)将其封装起来的代码块,要想执行这个函数,只要调用其函数名即可. 特性: 减少重复代码 使程序变的可扩展 使程 ...
- HDU--跑道相遇
跑道相遇 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hexo建个人博客
已经在腾讯云获得了域名和服务器,想着既然已经这样了,就折腾折腾自己的个人博客主页吧. 考虑再三决定用github pages来实现我的博客.github Pages可以被认为是用户编写的.托管在git ...
- 多文档上传(upload multiple documents)功能不能使用怎么办?
问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰 ...
- 面试题系列——OSI七层模型
OSI(开放式系统互联模型)是一个开放性的通行系统互连参考模型,是一个协议规范.它把网络协议从逻辑上分了七层,每一层都有对应的物理设备. OSI七层模型是一种框架性的设计方法,设计的主要目的是为了解决 ...
- Webix JavaScript UI 库可以帮你构建跨平台的HTML5 和 CSS3 程序
XB 软件公司最近发布了JavaScript UI 库Webix ,其中包含的组件超过45个,用这些组件可以构建跟HTML5 和 CSS3 兼容的程序,这些程序不仅能在个人电脑上运行,还能用在iOS. ...
- ABP理论学习之验证DTO
返回总目录 本篇目录 验证介绍 使用数据注解 自定义验证 标准化 验证介绍 首先应该验证应用的输入.用户或者其它应用都可以向该应用发送输入.在一个web应用中,验证通常要实现两次:在客户端和服务器端. ...
- 玩转JavaScript OOP[1]——复杂类型
概述 在JavaScript中,我们可以使用函数.数组.对象,以及日期.正则等一些内置类型的实例,它们都是复杂类型的表现.从本质上讲,这些复杂类型都是Object类型.本篇将主要介绍三种Object类 ...