【備份恢復】set newname切換日誌

不一樣的天空w發表於2016-10-17

使用 SET NEWNAME 切換檔案(相當於copyset newname 的作用是恢復到一個新的路徑

switch 做切換把新路徑檔案寫到控制檔案中恢復到一個新的路徑

1)   建立測試表空間,資料檔案放在/home/oracle/oradata/目錄下

——建立目錄:

[oracle@wang ~]$ mkdir oradata

[oracle@wang ~]$ cd oradata/

[oracle@wang oradata]$ ls

[oracle@wang oradata]$

[oracle@wang oradata]$ pwd

/home/oracle/oradata

——建立表空間:

SYS@ORA11GR2>create tablespace ts_xxf datafile '/home/oracle/oradata/ts_xxf_01.dbf' size 10m;

 

Tablespace created.

 

SYS@ORA11GR2>select file_name from dba_data_files where tablespace_name='TS_XXF';

 

FILE_NAME

----------------------------------------------------------------------------

/home/oracle/oradata/ts_xxf_01.dbf

2.透過RMAN切換資料檔案路徑

RMAN>  run

 {allocate channel c1 device type disk;

 sql "alter tablespace ts_xxf offline immediate";

 set newname for datafile '/home/oracle/oradata/ts_xxf_01.dbf' to '/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf';

 restore tablespace ts_xxf;

 switch datafile all;

 recover tablespace ts_xxf;

 sql "alter tablespace ts_xxf online";

 }

 

released channel: ORA_DISK_1

allocated channel: c1

channel c1: SID=21 device type=DISK

 

sql statement: alter tablespace ts_xxf offline immediate

 

executing command: SET NEWNAME

 

Starting restore at 02-OCT-16

 

creating datafile file number=6 name=/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf

restore not done; all files read only, offline, or already restored

Finished restore at 02-OCT-16

 

datafile 6 switched to datafile copy

input datafile copy RECID=3 STAMP=924173852 file name=/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf

 

Starting recover at 02-OCT-16

 

starting media recovery

media recovery complete, elapsed time: 00:00:01

 

Finished recover at 02-OCT-16

 

sql statement: alter tablespace ts_xxf online

released channel: c1

 

3.驗證

SYS@ORA11GR2>select file_name from dba_data_files where tablespace_name='TS_XXF';

 

FILE_NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf


SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf

/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf

 

SYS@ORA11GR2>

SYS@ORA11GR2>!ls /home/oracle/oradata/ts_xxf_01.dbf

/home/oracle/oradata/ts_xxf_01.dbf

 

SYS@ORA11GR2>!rm /home/oracle/oradata/ts_xxf_01.dbf

 

rmanSET NEWNAME,就是將其他目錄下的同名資料檔案複製到原目錄下去,利用的是RMAN工具!  切換完畢後,原目錄下還有資料檔案,刪除之即可。

主要內容命令如下:
run
 {allocate channel c1 device type disk;
 sql "alter tablespace ts_xxf offline immediate";
 set newname for datafile '/home/oracle/oradata/ts_xxf_01.dbf' to '/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf';
 restore tablespace ts_xxf;
 switch datafile all;
 recover tablespace ts_xxf;
 sql "alter tablespace ts_xxf online";
 }

alert日誌相應內容如下:
/////////////////////////////////////////
Thu Dec 07 23:19:11 2017
alter tablespace ts_xxf offline immediate
Completed: alter tablespace ts_xxf offline immediate
Switch of datafile 6 complete to datafile copy
  checkpoint is 3919138
alter database recover datafile list clear
Completed: alter database recover datafile list clear
alter database recover if needed
 tablespace TS_XXF
Media Recovery Start
Serial Media Recovery started
Recovery of Online Redo Log: Thread 1 Group 3 Seq 921 Reading mem 0
  Mem# 0: /u01/app/oracle/oradata/DBdb/redo03.log
Media Recovery Complete (DBdb)
Completed: alter database recover if needed
 tablespace TS_XXF
alter tablespace ts_xxf online
Completed: alter tablespace ts_xxf online
 /////////////////////////////////////////////////

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31397003/viewspace-2126536/,如需轉載,請註明出處,否則將追究法律責任。

相關文章