使用RMAN恢复数据库

由于需要搭建一个测试环境,把上周末的一个全备拿出来做恢复,首先备份一下测试库上现有的重要表:

exp banping/bangping@ERPTEST file=f:\20090905.dmp tables=(msgtaskdef,rptcol,rptdata)

然后把全备的备份片文件和控制文件COPY过来:

rcp p5b1:/orabak/ctl_file/c-2400249746-20090828-02 /orabak
rcp p5b1:/orabak/arch/* /orabak

文件属主给Oracle:

p5b2@/orabak#chown oracle.dba *

然后启动数据库到nomount状态,进入Rman环境,restore控制文件:

$ rman target /
RMAN> restore controlfile from '/orabak/ c-2400249746-20090828-02';

启动到mount状态:

RMAN> sql 'alter database mount';

根据测试库的环境重命名数据文件的位置:

run {
 allocate channel c1 device type disk;
 allocate channel c2 device type disk;
 set newname for datafile '/dev/rdb_system' to '/u02/oradata/erpdev2/rdb_system';
 set newname for datafile '/dev/rdb_undotbs1' to '/u02/oradata/erpdev2/rdb_undotbs1';
 set newname for datafile '/dev/rdb_sysaux' to '/u02/oradata/erpdev2/rdb_sysaux';
 set newname for datafile '/dev/rdb_undotbs2' to '/u02/oradata/erpdev2/rdb_undotbs2';
 set newname for datafile '/dev/rdb_users' to '/u02/oradata/erpdev2/rdb_users';
 set newname for datafile '/dev/rdb_erp' to '/u02/oradata/erpdev2/rdb_erp';
 set newname for datafile '/dev/rdb_erp_index' to '/u02/oradata/erpdev2/rdb_erp_index';
 set newname for datafile '/dev/rdb_erp_xm' to '/u02/oradata/erpdev2/rdb_erp_xm';
 set newname for datafile '/dev/rdb_erp_ht' to '/u02/oradata/erpdev2/rdb_erp_ht';
 set newname for datafile '/dev/rdb_erp_wl' to '/u02/oradata/erpdev2/rdb_erp_wl';
 set newname for datafile '/dev/rdb_erp_cw' to '/u02/oradata/erpdev2/rdb_erp_cw';
 set newname for datafile '/dev/rdb_erp_zj' to '/u02/oradata/erpdev2/rdb_erp_zj';
 set newname for datafile '/dev/rdb_erp_sp' to '/u02/oradata/erpdev2/rdb_erp_sp';
 set newname for datafile '/dev/rdb_cndwl' to '/u02/oradata/erpdev2/rdb_cndwl';
 set newname for datafile '/dev/rdb_xdwl' to '/u02/oradata/erpdev2/rdb_xdwl';
 set newname for datafile '/dev/rdb_sysaux2' to '/u02/oradata/erpdev2/rdb_sysaux2';
 set newname for datafile '/dev/rdb_erp2' to '/u02/oradata/erpdev2/rdb_erp2';
 set newname for datafile '/dev/rdb_erp_ht2' to '/u02/oradata/erpdev2/rdb_erp_ht2';
 restore database;
 switch datafile all;
}

然后执行recover操作:

RMAN> recover database;

这时数据库报错了:

Oracle Error:
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/u02/oradata/erpdev2/rdb_system'

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/04/2009 14:31:39
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of log thread 2 seq 106090 lowscn 10440022578 found to restore
RMAN-06025: no backup of log thread 2 seq 106089 lowscn 10440021828 found to restore
RMAN-06025: no backup of log thread 2 seq 106088 lowscn 10440020848 found to restore
RMAN-06025: no backup of log thread 2 seq 106087 lowscn 10440018779 found to restore
RMAN-06025: no backup of log thread 2 seq 106086 lowscn 10440007985 found to restore
RMAN-06025: no backup of log thread 2 seq 106085 lowscn 10439981571 found to restore
RMAN-06025: no backup of log thread 2 seq 106084 lowscn 10439980750 found to restore
RMAN-06025: no backup of log thread 1 seq 99356 lowscn 10440022588 found to restore
RMAN-06025: no backup of log thread 1 seq 99355 lowscn 10440021839 found to restore
RMAN-06025: no backup of log thread 1 seq 99354 lowscn 10440020856 found to restore
RMAN-06025: no backup of log thread 1 seq 99353 lowscn 10440018824 found to restore
RMAN-06025: no backup of log thread 1 seq 99352 lowscn 10440008036 found to restore
RMAN-06025: no backup of log thread 1 seq 99351 lowscn 10439981670 found to restore
RMAN-06025: no backup of log thread 1 seq 99350 lowscn 10439980746 found to restore

看来有些备份片不全,于是把全备后的备份片弄过来放到/orabak/arch目录,先注册到控制文件:

RMAN> catalog start with '/orabak/arch';

searching for all files that match the pattern /orabak/arch

List of Files Unknown to the Database
=====================================
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171285_15256_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171311_15258_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171617_15257_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171922_15259_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696172209_15260_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696172385_15261_1

Do you really want to catalog the above files (enter YES or NO)? y
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171285_15256_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171311_15258_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171617_15257_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696171922_15259_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696172209_15260_1
File Name: /orabak/arch/CNDERPDB_arch_20090829_696172385_15261_1

重新进行recover操作:

RMAN> recover database;

Starting recover at 07-SEP-09
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 99417 is already on disk as file /u02/ora_arch/1_99417_640266118.dbf
unable to find archive log
archive log thread=2 sequence=106154
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/07/2009 08:59:16
RMAN-06054: media recovery requesting unknown log: thread 2 seq 106154 lowscn 10444622603

继续找不到需要的备份片,尝试了几次后发现会一直这样找下去:

unable to find archive log
archive log thread=1 sequence=99470
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/07/2009 09:29:02
RMAN-06054: media recovery requesting unknown log: thread 1 seq 99470 lowscn 10444784948

由于测试用,指定SCN恢复:

RMAN> run {
2>              set until scn 10444783788;
3>              recover database ;
4> }

executing command: SET until clause

Starting recover at 07-SEP-09
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/07/2009 09:38:44
RMAN-06556: datafile 1 must be restored from backup older than scn 10444783788

这个通过list backup of archivelog all找出来的SCN竟然不对,继续把备份片拿回来,执行到刚才说缺失的10444784948号SCN进行恢复:

RMAN> run {
2>              set until scn 10444784948;
3>              recover database ;
4> }

executing command: SET until clause

Starting recover at 07-SEP-09
using channel ORA_DISK_1

starting media recovery

archive log thread 2 sequence 106205 is already on disk as file /u02/ora_arch/2_106205_640266118.dbf
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=99470
channel ORA_DISK_1: reading from backup piece /orabak/arch/CNDERPDB_arch_20090830_696257683_15267_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/orabak/arch/CNDERPDB_arch_20090830_696257683_15267_1 tag=TAG20090830T130014
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u02/ora_arch/1_99470_640266118.dbf thread=1 sequence=99470
archive log filename=/u02/ora_arch/2_106205_640266118.dbf thread=2 sequence=106205
media recovery complete, elapsed time: 00:00:03
Finished recover at 07-SEP-09

尝试打开后报错:

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/07/2009 09:57:10
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

RMAN> alter database open resetlogs;

RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
ORACLE error from target database:
ORA-19921: maximum number of 64 rows exceeded

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/07/2009 09:57:20
ORA-00344: unable to re-create online log '/dev/rdb_redo1_11'
ORA-27040: file create error, unable to create file
IBM AIX RISC System/6000 Error: 13: Permission denied

按照备份的文件,先在测试库建立一系列redo文件:

SQL> alter database rename file '/dev/rdb_redo1_11' to '/u02/oradata/erpdev2/rdb_redo1_1';

Database altered.

建立临时表空间文件,可以删除不必要的:

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
/dev/rdb_erp_temp
/dev/rdb_erp_temp2
/dev/rdb_erp_temp3

SQL> alter database rename file '/dev/rdb_erp_temp' to '/u02/oradata/erpdev2/rdb_erp_temp';

Database altered.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
/u02/oradata/erpdev2/rdb_erp_temp
/dev/rdb_erp_temp2
/dev/rdb_erp_temp3

SQL> alter database tempfile '/dev/rdb_erp_temp2' drop including datafiles;

Database altered.

SQL> alter database tempfile '/dev/rdb_erp_temp3' drop including datafiles;

Database altered.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
/u02/oradata/erpdev2/rdb_erp_temp

由于是不完全恢复,要resetlogs打开:

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;

Database altered.

查看归档模式:

SQL> archive log list    
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u02/ora_arch/
Oldest online log sequence     0
Next log sequence to archive   1
Current log sequence           1

关闭归档:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  603979776 bytes
Fixed Size                  2074704 bytes
Variable Size             318769072 bytes
Database Buffers          276824064 bytes
Redo Buffers                6311936 bytes
Database mounted.
SQL> alter database noarchivelog;

Database altered.

SQL> alter database open;

Database altered.

http://www.banping.com/2009/09/08/rman_recover_db/

使用RMAN恢复数据库的更多相关文章

  1. Oracle RMAN 恢复数据库到不同主机(二)

    我们在recover database时报一个错误: RMAN-06054: media recovery requesting unknown archived log for thread 1 w ...

  2. oracle rman恢复数据库 方式恢复到异地数据库

    目的:从某个环境中,获取相关文件,放到异地机器使用rman 恢复.   情况说明:XX系统使用的是oracle数据库,现已从服务器拉下来相关文件,依靠这些文件来早本地的测试机上恢复数据库,方便进行数据 ...

  3. Oracle RMAN 恢复数据库到不同主机(一)

    一.RMAN 备份的内容 RMAN做数据库全备时包含了 数据文件.归档日志.控制文件和参数文件和备份日志,如下: arch_20160223_08qukp2t_1_1  arch_20160223_0 ...

  4. RMAN备份数据库与恢复数据库(整库)

    1 准备 2 1.1 检查数据库归档状态 2 1.2 RMAN登陆目标 2 2 备份全库 2 2.1 创建备份数据存储目录 2 2.2 RMAN备份全库 2 2.3 试验(备份后,改变数据) 5 2. ...

  5. 【12c】12c RMAN新特性之通过网络远程恢复数据库(RESTORE/Recover from Service)

    [12c]12c RMAN新特性之通过网络远程恢复数据库(RESTORE/Recover from Service) 通过网络远程恢复数据库(Restore/Recover from Service) ...

  6. 利用RMAN恢复整个数据库

    利用RMAN恢复整个数据库案例一 适合场合:恢复的目录一致,同时备份的过程中有归档日志 恢复的数据库目录和down机的数据库一致,还有一个就是RMAN备份的时候已经备份了归档日志. 备份脚本: run ...

  7. RAC+asm通过rman恢复到单实例+asm

    1.恢复参数文件,并修改参数文件 参数文件指名几个最简单的就行,我的参数文件如下: 2.恢复控制文件,并启动数据库到mount 如果是把备份集从别的服务器拷贝到本地恢复的服务器的目录,使用下面的语句指 ...

  8. Oracle RMAN 恢复控制文件到指定的路径

    Oracle 数据库通过RMAN恢复控制文件到指定的路径 --------------------------------------------------------- 先查询备份集信息,再指定备 ...

  9. RMAN恢复目录

    是否使用RMAN恢复目录(Recovery Catalog 你可能从其他人或书上听过RMAN恢复目录(也有可能是其他名字,RMAN Recovery Catalog的翻译较多较杂,以下简称恢复目录), ...

随机推荐

  1. 组件的 render 方法

    React.js 中一切皆组件,用 React.js 写的其实就是 React.js 组件.我们在编写 React.js 组件的时候,一般都需要继承 React.js 的 Component(还有别的 ...

  2. Git之fatal: remote origin already exists

    文件提交到远程分支,我们需要提前表明需要提交到哪个远程分支 比如:git remote add origin git@github.com:wqk66/test.git,表示他提交到远程仓库test ...

  3. 【学习笔记】深入理解js原型和闭包(11)——执行上下文栈

    继续上文的内容. 执行全局代码时,会产生一个执行上下文环境,每次调用函数都又会产生执行上下文环境.当函数调用完成时,这个上下文环境以及其中的数据都会被消除,再重新回到全局上下文环境.处于活动状态的执行 ...

  4. Java网络编程学习笔记

    Java网络编程,我们先来看下面这一张图: 由图可得:想要进行网络编程,首先是服务器端通过ServerSocket对某一个端口进行监听.通过accept来判断是否有客户端与其相连.若成功连上,则通过r ...

  5. elasticsearch 2.4在head删除数据(使用Delete By Query插件)

    之所以说明是2.4版,是因为不同版本删除的语法不一样(例如跟5.x就不同) 首先安装Delete By Query插件,方式跟安装head插件差不多,安装命令:plugin install delet ...

  6. [转载]ant和maven的区别

    Ant是软件构建工具,Maven的定位是软件项目管理和理解工具.Maven除了具备Ant的功能外,还增加了以下主要的功能: 1)使用Project Object Model来对软件项目管理: 2)内置 ...

  7. 汇编2.汇编版本的helloworld

    寻址方式 立即数寻址 寄存器寻址 存储器寻址 直接寻址 : mov ax, [ 01000h ]; 直接在[]内给出一个内存地址 寄存器间接寻址: mov ax ,[si]; 在[]以寄存器的值给出内 ...

  8. iview modal 点击打开窗口,打开前先销毁里面的内容再打开

    <Modal v-model="addSubOrgModal" @on-cancel="addSubOrgCancel" @on-visible-chan ...

  9. Open Cascade:使用鼠标画线

    Open Cascade:使用鼠标画线 在View类文件中创建以下代码: 1.创建鼠标消息: afx_msg void OnLButtonDown(UINT nFlags, CPoint point) ...

  10. [SQL]连续三天有销售额

    店铺 销售日期 销售额 A 2017-10-11 300 A 2017-10-12 200 B 2017-10-11 400 B 2017-10-12 200 A 2017-10-13 100 A 2 ...