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

上一篇:node.js 读取文件


下一篇:[Android] 给图像添加相框、圆形圆角显示图片、图像合成知识