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

简介: [20170105]关于使用datafilecopy恢复.txt --如果指定恢复数据文件是从datafilecopy,必须加括号,写一个例子说明: 1.环境: SYS@book> @ &r/ver1 PORT_STRING             ...

[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 ;要使用括号.

目录
相关文章
|
SQL Oracle 关系型数据库
[20171225]没有备份数据文件的恢复.txt
[20171225]没有备份数据文件的恢复.txt --//别人问的问题,增加了数据文件没有备份,如何恢复,实际上很简单,因为当前控制文件有记录建立时间只要从建立数据文件开始的 --//归档日志都存在恢复是没有任何问题的.
909 0
|
监控 Oracle 关系型数据库
[20171208]强制删除归档日志文件.txt
[20171208]强制删除归档日志文件.txt --//测试环境,产生日志太多,想强制删除. RMAN> delete archivelog all ; released channel: ORA_DISK_1 allocated channel: ORA...
1428 0
|
Oracle 关系型数据库 数据库
[20171122]恢复数据文件块头5.txt
[20171122]恢复数据文件块头5.txt --//前几天做了恢复数据文件块头,通过备份文件直接取出文件块头,覆盖原来的数据块,然后修复. --//今天测试使用image copy来恢复.
1120 0
|
Oracle 关系型数据库 数据库
[20171114]恢复数据文件块头2.txt
[20171114]恢复数据文件块头2.txt --//曾经写过一篇[20161111]数据库文件头的修复.txt,但是利用大小相似的数据文件头覆盖来恢复,那是属于特种恢复.
1079 0
|
Oracle 关系型数据库 数据库
[20171115]恢复数据文件块头4补充.txt
[20171115]恢复数据文件块头4补充.txt --// 昨天做了恢复数据文件块头,通过备份文件直接取出文件块头,覆盖原来的数据块,然后修复. --//补充几点: --1.
1061 0
|
Oracle 关系型数据库 数据库管理
[20171115]恢复数据文件块头3补充.txt
[20171115]恢复数据文件块头3补充.txt --// 昨天做了恢复数据文件块头,通过备份文件直接取出文件块头,覆盖原来的数据块,然后修复. --//补充几点: --1.
1139 0
|
Oracle 关系型数据库 数据库
[20171031]rman备份压缩模式.txt
[20171031]rman备份压缩模式.txt --//测试rman备份压缩模式,那种效果好,我记忆里选择medium在备份时间和备份文件大小综合考虑最佳. --//还是通过脚本测试: 1.
1238 0
|
SQL Oracle 关系型数据库
[20170627]使用TSPITR恢复表空间.txt
[20170627]使用TSPITR恢复表空间.txt --//RMAN提供了一种实现所谓TSPITR(Tablespace Point-In-Time Recovery)的技术,通过简单的一个语句,就可以在主库不停库(很吸引人) --//的情况下,利用备份集和连续的归档日志,实现表空间级别的定点恢复。
896 0
|
数据库管理
[20170411]bbed删除记录的恢复.txt
[20170411]bbed删除记录的恢复.txt --//昨天上午做的测试,链接:http://blog.itpub.net/267265/viewspace-2136933/ --//我当时并没有选择恢复记录,仅仅看删除的内容.
1043 0
|
关系型数据库 测试技术 数据库
[20170322]实例crash恢复2.txt
[20170322]实例crash恢复2.txt 如果发生了实例崩溃,只需要在日志文件中找到检查点位置(low cache rba),从此开始应用所有的重做日志文件, 就完成了前滚操作。
815 0