[20170105]关于使用datafilecopy恢复.txt

[20170105]关于使用datafilecopy恢复.txt

--如果指定恢复数据文件是从datafilecopy,必须加括号,写一个例子说明:
1.环境:
SYS@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

RMAN> report schema ;
Report of database schema for database with db_unique_name BOOK
List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    760      SYSTEM               ***     /mnt/ramdisk/book/system01.dbf
2    770      SYSAUX               ***     /mnt/ramdisk/book/sysaux01.dbf
3    85       UNDOTBS1             ***     /mnt/ramdisk/book/undotbs01.dbf
4    125      USERS                ***     /mnt/ramdisk/book/users01.dbf
5    346      EXAMPLE              ***     /mnt/ramdisk/book/example01.dbf
6    10       TEA                  ***     /mnt/ramdisk/book/tea01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    38       TEMP                 32767       /mnt/ramdisk/book/temp01.dbf

2.备份使用copy模式:

RMAN> backup as copy datafile 6 format '/u01/backup/%b';
Starting backup at 2017-01-05 10:40:42
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
output file name=/u01/backup/tea01.dbf tag=TAG20170105T104042 RECID=8 STAMP=932467242
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2017-01-05 10:40:43

Starting Control File and SPFILE Autobackup at 2017-01-05 10:40:43
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_01_05/o1_mf_s_932467243_d6vdkc97_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-01-05 10:40:44

--//注意1个细节%b表示备份文件名跟原来一样(去除路径).但是仅仅使用小写的%b,如果大写,备份的文件是%B.

RMAN> sql 'alter database datafile 6 offline ';
sql statement: alter database datafile 6 offline

RMAN> restore datafile 6 from datafilecopy ;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "datafilecopy": expecting one of: "autobackup, tag, double-quoted-string, single-quoted-string"
RMAN-01007: at line 1 column 25 file: standard input

--//指定括号才能通过.
RMAN> restore (datafile 6)  from datafilecopy ;
Starting restore at 2017-01-05 10:42:35
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3

channel ORA_DISK_1: restoring datafile 00006
input datafile copy RECID=8 STAMP=932467242 file name=/u01/backup/tea01.dbf
destination for restore of datafile 00006: /mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00006
output file name=/mnt/ramdisk/book/tea01.dbf RECID=0 STAMP=0
Finished restore at 2017-01-05 10:42:36

--当然如果没有后面的from datafilecopy 参数,oracle也能找到.offline后再次restore,执行如下:
RMAN> restore datafile 6;
Starting restore at 2017-01-05 10:43:21
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: restoring datafile 00006
input datafile copy RECID=8 STAMP=932467242 file name=/u01/backup/tea01.dbf
destination for restore of datafile 00006: /mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00006
output file name=/mnt/ramdisk/book/tea01.dbf RECID=0 STAMP=0
Finished restore at 2017-01-05 10:43:23

RMAN> recover datafile 6;
Starting recover at 2017-01-05 10:45:45
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2017-01-05 10:45:45

RMAN> sql 'alter database datafile 6 online ';
sql statement: alter database datafile 6 online

3.继续测试:
RMAN> backup  datafile 6 format '/u01/backup/data6_%U';
Starting backup at 2017-01-05 10:50:24
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: starting piece 1 at 2017-01-05 10:50:24
channel ORA_DISK_1: finished piece 1 at 2017-01-05 10:50:25
piece handle=/u01/backup/data6_4brp8l3g_1_1 tag=TAG20170105T105024 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-01-05 10:50:25

Starting Control File and SPFILE Autobackup at 2017-01-05 10:50:25
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_01_05/o1_mf_s_932467825_d6vf3kd3_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-01-05 10:50:26

--这样就建立2个备份.看看恢复优先选择那个.

RMAN> sql 'alter database datafile 6 offline ';
sql statement: alter database datafile 6 offline

RMAN> restore datafile 6;
Starting restore at 2017-01-05 10:51:48
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3

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 00006 to /mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/data6_4brp8l3g_1_1
channel ORA_DISK_1: piece handle=/u01/backup/data6_4brp8l3g_1_1 tag=TAG20170105T105024
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2017-01-05 10:51:49

--//可以看出还是选择最近的备份集.

RMAN> recover datafile 6;
Starting recover at 2017-01-05 10:52:39
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2017-01-05 10:52:39

RMAN> sql 'alter database datafile 6 online ';
sql statement: alter database datafile 6 online

总结:
1.%b 要小写.
2.restore (datafile 6)  from datafilecopy ;要使用括号.

时间: 2024-10-23 18:21:46

[20170105]关于使用datafilecopy恢复.txt的相关文章

[20171121]rman使用copy image恢复.txt

[20171121]rman使用copy image恢复.txt --//上个星期做数据文件块头恢复时,提到使用rman备份数据文件时,文件头数据库信息是最后写入备份集文件的,在filesperset=1的情况 --//下写入备份集文件中的倒数第2块就是文件头的备份.参考链接: http://blog.itpub.net/267265/viewspace-2147297/=>[20171115]恢复数据文件块头4补充.txt --//而且我最后还做了测试证明如果resotre数据文件,实际上文件

[20170411]bbed删除记录的恢复.txt

[20170411]bbed删除记录的恢复.txt --//昨天上午做的测试,链接:http://blog.itpub.net/267265/viewspace-2136933/ --//我当时并没有选择恢复记录,仅仅看删除的内容.因为这样恢复是存在许多问题. --//执行 drop function scott.sleep ; 删除sys.source$相关记录仅仅是该命令的一小部分,恢复 --//sys.source$相关记录会存在许多问题,但是如果是应用数据恢复还是可以,实际上以前我的博客

[20141218]误操作删除dual表的恢复.txt

[20141218]误操作删除dual表的恢复.txt --没事,做一个误操作删除dual表的恢复,没想到不能按照网上介绍的方法恢复,做一个记录. 1.建立测试数据库: mkdir -p /mnt/ramdisk mount -t tmpfs -o size=8G tmpfs /mnt/ramdisk $ORACLE_HOME/bin/dbca -createDatabase -templateName General_Purpose.dbc -gdbName test -sid test -s

[20150430]列删除的简单恢复.txt

[20150430]列删除的简单恢复.txt SCOTT@test> @ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- -------------------------------------------------------------------------------- x86_64/Linux 2.4.xx          

[20140507]实例crash恢复.txt

[20140507]实例crash恢复.txt 如果发生了实例崩溃,只需要在日志文件中找到检查点位置(low cache rba),从此开始应用所有的重做日志文件, 就完成了前滚操作. 实例崩溃后,再次启动数据库,oracle会到控制文件中读取low cache rba,这就是检查点位置. 从此处开始应用重做日志,应用到on disk rba的位置.on disk rba是磁盘中重做日志文件的最后一条重做记录的rba. 加快恢复速度,确定恢复日志的起点. 不管redo记录的事务提交还是非提交,都

[20120906]alter table set unused column后的恢复.txt

[20120906]alter table set unused column后的恢复.txt 我们知道表在alter table 表 set unused column 字段名 后的恢复,数据并没有真正的删除,昨天开发问如果出现误操作是否能够恢复(概率也太小了). 大家知道在执行以上操作后,执行很快,对应字段的数据并没有真正删除,自己觉得好奇,测试看看. 1.测试环境: SQL> select * from v$version ; BANNER ------------------------

[20120925]truncate的恢复.txt

[20120925]truncate的恢复.txt 1.做好备份: RMAN> delete archivelog all completed before 'sysdate-8/24' ; RMAN> backup database format '/data/testtest/%U'; Starting backup at 2012-09-25 10:25:08using channel ORA_DISK_1channel ORA_DISK_1: starting full datafil

[20130530]OS block header破坏以及恢复.txt

[20130530]OS block header破坏以及恢复.txt oracle文件的第一个块(block 0)是OS block header,在数据库中查询不到信息,记录的是OS信息,以及文件大小的等信息: 如果损坏,应该对数据文件影响大吗? 自己做一个测试看看. 1.介绍OS block header:@verSQL> @verBANNER--------------------------------------------------------------------------

[20130425]使用vim编辑没有保存的恢复.txt

今天使用vim编辑一个存储过程的时候,正好接听一个电话,不知道什么回事,点击X,选择"否",导致将近半个小时的工作没有保存下 来. 我冷静下来,想起使用vim会在它的dir目录保存为"原来文件名.swp". 我的vim设置如下: set dir=d:\\temp缺省如果不设置,保存在当前目录. 知道这个就很好办了,使用EasyRecovery.exe恢复工具,恢复这个文件并且放回原来的位置. 再次使用vim打开文件.会提示交换文件 "d:\temp\xxx