linux下仅仅有rman备份集的异机不同文件夹恢复
昨天在客户那里做了一次rman异机的恢复,把生产库弄一份给測试库用,总库大概80G,总共花费了2个小时,当时客户的环境是windows 11.2.0.3,今天早晨在linux下又一次測试了一下,记录下来供大家參考
环境:
全部操作都是按主机名区分
源库:
主机名 bre1 实例名为bre1 数据文件文件夹在/u01/app/oradata下
目标库:
主机名 bre2 数据文件准备放在/bre1/oradata下
废话不多说,以下是实际操作步骤
1.在源库创建备份集,而且复制到目标库
拷贝的文件夹可用和原来的备份的时候的文件夹一致,也能够不一致
备份system表空间rman会自己主动备份參数文件和控制文件
RMAN> backup database format '/home/oracle/%U.bak'; Starting backup at 21-AUG-2014 10:03:35
using channel ORA_DISK_1
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/bre1/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/bre1/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/bre1/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/bre1/test.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/bre1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 21-AUG-2014 10:03:36
channel ORA_DISK_1: finished piece 1 at 21-AUG-2014 10:03:51
piece handle=/home/oracle/03pggb7o_1_1.bak tag=TAG20140821T100336 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
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 21-AUG-2014 10:03:52
channel ORA_DISK_1: finished piece 1 at 21-AUG-2014 10:03:53
piece handle=/home/oracle/04pggb87_1_1.bak tag=TAG20140821T100336 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 21-AUG-2014 10:03:53 [oracle@bre2 ~]$ scp bre1:/home/oracle/03pggb7o_1_1.bak .
The authenticity of host 'bre1 (192.168.56.45)' can't be established.
RSA key fingerprint is 73:56:4c:3a:01:3f:50:c8:d8:3a:5d:d5:21:00:6a:fe.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bre1,192.168.56.45' (RSA) to the list of known hosts.
oracle@bre1's password:
03pggb7o_1_1.bak 100% 336MB 37.3MB/s 00:09
[oracle@bre2 ~]$ scp bre1:/home/oracle/04pggb87_1_1.bak .
oracle@bre1's password:
04pggb87_1_1.bak 100% 9600KB 9.4MB/s 00:00
2.还原spfile,使用nomount打开数据库
编辑一个最简单的pfile,仅仅有db_name就可以:
[oracle@bre2 dbs]$ vi initbre1.ora
[oracle@bre2 dbs]$ cat initbre1.ora
db_name=bre1
然后就能够nomount打开数据库了:
SQL> startup nomount;
ORACLE instance started. Total System Global Area 229683200 bytes
Fixed Size 2251936 bytes
Variable Size 171967328 bytes
Database Buffers 50331648 bytes
Redo Buffers 5132288 bytes
SQL>
再使用rman来恢复spfile:
RMAN> restore spfile from '/home/oracle/backup/04pggb87_1_1.bak'; Starting restore at 21-AUG-2014 9:39:31
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 /home/oracle/backup/04pggb87_1_1.bak
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 21-AUG-2014 9:39:32 RMAN>
使用spfile来打理数据库试试
[oracle@bre2 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 21 10:08:01 2014 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db_1/dbs/initbre1.ora'
SQL> startup nomount;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db_1/dbs/initbre1.ora'
SQL> startup nomount;
ORA-09925: Unable to create audit trail file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9925
有非常多相关文件夹没有创建,能够使用strings spfilebre1.ora来查看一下spfile里面的内容,建好相关的文件夹,而且赋予权限。。这些都搞好后nomount打开数据库不再报错。
3.恢复控制文件
登陆到rman,控制文件还原的时候将还原到參数文件指定的位置,所以參数文件指定的控制文件文件夹必须存在,否则报错,比如以下一開始我没有创建就报错,后来创建完毕就不报错了,假设你想还原到其它地方,能够改动參数文件指定到对应地址。
RMAN> restore controlfile from '/home/oracle/04pggb87_1_1.bak'; Starting restore at 21-AUG-2014 10:26:14
using channel ORA_DISK_1 channel ORA_DISK_1: restoring control file
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 08/21/2014 10:26:15
ORA-19870: error while restoring backup piece /home/oracle/04pggb87_1_1.bak
ORA-19504: failed to create file "/u01/app/oracle/oradata/bre1/control01.ctl"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1 RMAN> restore controlfile from '/home/oracle/04pggb87_1_1.bak'; Starting restore at 21-AUG-2014 10:26:50
using channel ORA_DISK_1 channel ORA_DISK_1: restoring control file
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 08/21/2014 10:26:51
ORA-19504: failed to create file "/u01/app/oracle/fast_recovery_area/bre1/control02.ctl"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1
ORA-19600: input file is control file (/u01/app/oracle/oradata/bre1/control01.ctl)
ORA-19601: output file is control file (/u01/app/oracle/fast_recovery_area/bre1/control02.ctl) RMAN> restore controlfile from '/home/oracle/04pggb87_1_1.bak'; Starting restore at 21-AUG-2014 10:27:24
using channel ORA_DISK_1 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/bre1/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/bre1/control02.ctl
Finished restore at 21-AUG-2014 10:27:25
4.mount数据库,注冊备份集
重新启动数据库,直接就能够启动到mount
SQL> startup mount;
ORACLE instance started. Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 503319632 bytes
Database Buffers 322961408 bytes
Redo Buffers 6565888 bytes
Database mounted.
SQL>
假设此时备份集所在文件文件夹改变,须要手工catalog注冊备份集,这里我们将拷过来的备份文件拷贝到/home/oracle/backup下,演示一下手工catalog备份集
[oracle@bre2 ~]$ ls
03pggb7o_1_1.bak 04pggb87_1_1.bak pfile.ora test
[oracle@bre2 ~]$ mkdir backup
[oracle@bre2 ~]$ mv *.bak backup
[oracle@bre2 ~]$ ls backup
03pggb7o_1_1.bak 04pggb87_1_1.bak RMAN> catalog backuppiece '/home/oracle/backup/03pggb7o_1_1.bak'; Starting implicit crosscheck backup at 21-AUG-2014 10:32:10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 21-AUG-2014 10:32:10 Starting implicit crosscheck copy at 21-AUG-2014 10:32:10
using channel ORA_DISK_1
Finished implicit crosscheck copy at 21-AUG-2014 10:32:11 searching for all files in the recovery area
cataloging files...
no files cataloged cataloged backup piece
backup piece handle=/home/oracle/backup/03pggb7o_1_1.bak RECID=2 STAMP=856175531 RMAN> catalog backuppiece '/home/oracle/backup/04pggb87_1_1.bak'; cataloged backup piece
backup piece handle=/home/oracle/backup/04pggb87_1_1.bak RECID=3 STAMP=856175550
5.使用set newname将数据文件还原到不同文件夹
原来的数据文件文件夹在/u01/admin/oradata以下,我们将数据文件恢复到/bre1/oradata以下,%b的意思是仅仅获取文件名称,没有文件夹信息
[root@bre2 ~]# mkdir -p /bre1/oradata
[root@bre2 ~]# chown -R oracle:oinstall /bre1 [oracle@bre2 ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Thu Aug 21 10:36:10 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: BRE1 (DBID=2522432392, not open) run{
allocate channel ch1 device type disk;
set newname for database to '/bre1/oradata/%b';
restore database;
release channel ch1;
6> } using target database control file instead of recovery catalog
allocated channel: ch1
channel ch1: SID=396 device type=DISK executing command: SET NEWNAME Starting restore at 21-AUG-2014 10:38:03 channel ch1: starting datafile backup set restore
channel ch1: specifying datafile(s) to restore from backup set
channel ch1: restoring datafile 00001 to /bre1/oradata/system01.dbf
channel ch1: restoring datafile 00002 to /bre1/oradata/sysaux01.dbf
channel ch1: restoring datafile 00003 to /bre1/oradata/undotbs01.dbf
channel ch1: restoring datafile 00004 to /bre1/oradata/users01.dbf
channel ch1: restoring datafile 00005 to /bre1/oradata/test.dbf
channel ch1: reading from backup piece /home/oracle/backup/03pggb7o_1_1.bak
channel ch1: piece handle=/home/oracle/backup/03pggb7o_1_1.bak tag=TAG20140821T100336
channel ch1: restored backup piece 1
channel ch1: restore complete, elapsed time: 00:00:45
Finished restore at 21-AUG-2014 10:38:48 released channel: ch1 数据文件都在了:
[root@bre2 ~]# ls -l /bre1/oradata
total 1564468
-rw-r----- 1 oracle oinstall 629153792 Aug 21 10:38 sysaux01.dbf
-rw-r----- 1 oracle oinstall 734011392 Aug 21 10:38 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 Aug 21 10:38 test.dbf
-rw-r----- 1 oracle oinstall 209723392 Aug 21 10:38 undotbs01.dbf
-rw-r----- 1 oracle oinstall 6561792 Aug 21 10:38 users01.dbf
资料上说能够使用switch datafile all来直接改动控制文件里的文件文件夹,可是我试了一下貌似不行,还是须要在手工rename,以下是我手工改动控制文件里的数据文件文件夹,先看一下当前的数据文件文件夹
SQL> select name from v$datafile; NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/bre1/system01.dbf
/u01/app/oracle/oradata/bre1/sysaux01.dbf
/u01/app/oracle/oradata/bre1/undotbs01.dbf
/u01/app/oracle/oradata/bre1/users01.dbf
/u01/app/oracle/oradata/bre1/test.dbf SQL> select name from v$tempfile; NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/bre1/temp01.dbf SQL> select member from v$logfile; MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/bre1/redo01.log
/u01/app/oracle/oradata/bre1/redo02.log
/u01/app/oracle/oradata/bre1/redo03.log
我自己写了一个拼接sql来将数据文件文件夹做转换:
select 'alter database rename file '''||name||''' to ''/bre1/oradata'||substr(name,length(name)-INSTR(reverse(name),'/')+1,INSTR(reverse(name),'/'))||''';' from v$datafile
union all
select 'alter database rename file '''||name||''' to ''/bre1/oradata'||substr(name,length(name)-INSTR(reverse(name),'/')+1,INSTR(reverse(name),'/'))||''';' from v$tempfile
union all
select 'alter database rename file '''||member||''' to ''/bre1/oradata'||substr(member,length(member)-INSTR(reverse(member),'/')+1,INSTR(reverse(member),'/'))||''';' from v$logfile
;
select 'alter database rename file '''||name||''' to ''/bre1/oradata'||substr(name,length(name)-INSTR(reverse(name),'/')+1,INSTR(reverse(name),'/'))||''';' from v$datafile
union all
select 'alter database rename file '''||name||''' to ''/bre1/oradata'||substr(name,length(name)-INSTR(reverse(name),'/')+1,INSTR(reverse(name),'/'))||''';' from v$tempfile
union all
select 'alter database rename file '''||member||''' to ''/bre1/oradata'||substr(member,length(member)-INSTR(reverse(member),'/')+1,INSTR(reverse(member),'/'))||''';' from v$logfile
6 ; 'ALTERDATABASERENAMEFILE'''||NAME||'''TO''/BRE1/ORADATA'||SUBSTR(NAME,LENGTH(NAME)-INSTR(REVERSE(NAME),'/')+1,INSTR(REVERSE(NAME),'/'))||''';'
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
alter database rename file '/bre1/oradata/system01.dbf' to '/bre1/oradata/system01.dbf';
alter database rename file '/bre1/oradata/sysaux01.dbf' to '/bre1/oradata/sysaux01.dbf';
alter database rename file '/bre1/oradata/undotbs01.dbf' to '/bre1/oradata/undotbs01.dbf';
alter database rename file '/bre1/oradata/users01.dbf' to '/bre1/oradata/users01.dbf';
alter database rename file '/bre1/oradata/test.dbf' to '/bre1/oradata/test.dbf';
alter database rename file '/u01/app/oracle/oradata/bre1/temp01.dbf' to '/bre1/oradata/temp01.dbf';
alter database rename file '/bre1/oradata/redo01.log' to '/bre1/oradata/redo01.log';
alter database rename file '/bre1/oradata/redo02.log' to '/bre1/oradata/redo02.log';
alter database rename file '/bre1/oradata/redo03.log' to '/bre1/oradata/redo03.log'; alter database rename file '/u01/app/oracle/oradata/bre1/system01.dbf' to '/bre1/oradata/system01.dbf';
alter database rename file '/u01/app/oracle/oradata/bre1/sysaux01.dbf' to '/bre1/oradata/sysaux01.dbf';
alter database rename file '/u01/app/oracle/oradata/bre1/undotbs01.dbf' to '/bre1/oradata/undotbs01.dbf';
alter database rename file '/u01/app/oracle/oradata/bre1/users01.dbf' to '/bre1/oradata/users01.dbf';
alter database rename file '/u01/app/oracle/oradata/bre1/test.dbf' to '/bre1/oradata/test.dbf';
alter database rename file '/u01/app/oracle/oradata/bre1/redo01.log' to '/bre1/oradata/redo01.log';
alter database rename file '/u01/app/oracle/oradata/bre1/redo02.log' to '/bre1/oradata/redo02.log'; Database altered. SQL>
Database altered. SQL>
Database altered. SQL>
Database altered. SQL>
Database altered.
SQL>
Database altered. SQL>
Database altered. SQL> alter database rename file '/u01/app/oracle/oradata/bre1/redo03.log' to '/bre1/oradata/redo03.log'; Database altered.
rename之后控制文件里的数据文件文件夹都已经改到了/bre1/oradata下,那么就能够进行恢复了。
6.恢复数据库
我这里是測试就没有恢复什么归档日志,假设是正式生产库,还须要恢复归档日志,可能还须要使用到CATALOG ARCHIVELOG 来注冊归档的备份集和在RMAN中使用
RUN
{
SET ARCHIVELOG DESTINATION TO '/home/oracle';
RESTORE ARCHIVELOG all;
}
来还原出归档日志。
或者还能够在controlfile中改动归档文件夹来恢复。恢复出归档日志之后,就能够进行数据库恢复。
[oracle@bre2 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 21 11:16:06 2014 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> recover database using backup controlfile until cancel;
ORA-00279: change 830841 generated at 08/21/2014 10:03:36 needed for thread 1
ORA-00289: suggestion : /arch1_42_851018056.dbf
ORA-00280: change 830841 for thread 1 is in sequence #42 Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SQL> alter database open resetlogs; Database altered.
open 过程中可能会遇到ora-00392错误,
解决的方法:
使用SQL> alter database clear logfile group 2;
到此恢复成功!
总结:
基本的难点是须要对rman比較熟悉,须要使用语句改动控制文件里的文件位置,否则会报错找不到相关文件。
假设备份集的文件夹改变了,须要手工catalog注冊备份集到控制文件,而且rename file。
linux下仅仅有rman备份集的异机不同文件夹恢复的更多相关文章
- RMAN备份策略与异机恢复一例(续篇)
本文是<RMAN备份策略与异机恢复一例>的续篇,继续实验验证,最终实现两个需求: 1.异机恢复临时测试的小库 2.传输归档时,实现增量传输 1.异机恢复临时测试的小库 之前异机恢复的需求已 ...
- RMAN备份策略与异机恢复一例
实验环境: A机器(生产用途):RHEL 6.5 + Oracle 11.2.0.4 + IP Address 192.168.1.11 B机器(备机用途):RHEL 6.5 + Oracle 11. ...
- Linux下的一个高速跳转到上N层文件夹的简单方法
编辑文件 vim .bashrc (使改动在当前用户下有效) 或者 vim /etc/profile (须要在root用户下运行,使改动在全部用户下有效) 在文件结尾加入别名 alias cd1=' ...
- linux下新建(mkdir)、删除(rmdir)文件夹
mkdir: 该命令:mkdir ./folder2/folder3 ./当前文件下下一级目录 rmdir:移除文件夹
- linux下使用crontab定时备份MYSQL数据库的方法:
摘要 linux下使用crontab定时备份MYSQL数据库的方法: 只需按照下面3步做,一切都在你的掌控之下: 第一步:在服务器上配置备份目录代码: ------------------------ ...
- oracle使用rman备份集恢复方式创建ADG
一.背景 系统: 主库:rhel 6.4 64bit 备库:rhel 6.4 64bit 内存:2G [oracle@dgdb1 ~]$ free -m total used free share ...
- 程序员(媛)Shell脚本必备技能之中的一个: 在Linux下怎样自己主动备份mysql数据
作者:荀彧(花名) Background:鉴于QAS数据库曾遭到毁灭性损害.极其桑心L.为了避免这样的玉石俱焚的状况再度发生.于是我们找出了一种应对方案.这里给大家分享一下怎样实现定时备份mysql数 ...
- 调皮捣蛋的Linux下有趣终端的合集
*本文作者:国光,转载自 FreeBuf.COM,原文地址:https://www.freebuf.com/news/144050.html 前言 刚开始接触Linux的我们,肯定认为Linux系统就 ...
- Linux下c函数dlopen实现加载动态库so文件代码举例
dlopen()是一个强大的库函数.该函数将打开一个新库,并把它装入内存.该函数主要用来加载库中的符号,这些符号在编译的时候是不知道的.这种机制使得在系统中添加或者删除一个模块时,都不需要重新编译了. ...
随机推荐
- P2P平台很赚钱么?
最近几年,搞P2P网贷和财富投资相关的金融周边公司,多了很多,楼下门店和电梯里的贷款小广告,真是多啊. 大家都去搞一件事的时候,很可能是大家都觉得这件事有利可图.但事实是,赚钱的总是少数,看到别人搞的 ...
- 原生js大总结一
001.浅谈堆和栈的理解? js变量存储有栈存储和堆存储,基本数据类型的变量存储在栈中,引用数据类型的变量存储在堆中 引用类型数据的地址也存在栈中 当访问基础类型变量时,直接从栈中取值.当访问 ...
- Android 最火的高速开发框架AndroidAnnotations使用具体解释
Android 最火的高速开发框架androidannotations配置具体解释文章中有eclipse配置步骤.Android 最火高速开发框架AndroidAnnotations简介文章中的简介. ...
- LA 5902 - Movie collection 树状数组(Fenwick树)
看题传送门 题目大意:XXX喜欢看电影,他有好多好多的影碟,每个影碟都有个独立的编号.开始是从下往上影碟的顺序是n~1,他每次拿出影碟的时候,你需要输出压在该影碟上的有几个.(拿出后其他影碟顺序不变) ...
- [TypeScript] Sharing Class Behavior with Inheritance in TypeScript
Typescript classes make inheritance much easier to write and understand. In this lesson we look into ...
- MHA 一主两从搭建-keepalived-手动切换
环境介绍:主机名 IP MHA角色 MySQL角色node1 192.168.56.26 Node MySQL Master node2 192.168.56.27 Node MySQL Master ...
- ZOJ 3204 Connect them 继续MST
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3367 题目大意: 让你求最小生成树,并且按照字典序输出哪些点连接.无解输出-1 ...
- JS生成一个种子随机数(伪随机数)
原文链接:https://geniuspeng.github.io/2016/09/12/js-random/ 最近有一个需求,需要生成一个随机数,但是又不能完全随机,就是说需要一个种子seed,se ...
- 【u106】3D模型
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 一座城市建立在规则的n×m网格上,并且网格均由1×1正方形构成.在每个网格上都可以有一个建筑,建筑由若 ...
- VCS编译仿真警告Warning
VCS编译仿真警告Warning 问题描述 在较大的SOC集成中,通常使用Perl脚本例化子模块到Top层,然而,有时会出现例化出来的输入端口名没有在Top层定义,而且端口的位宽为1bit,那么,ve ...