SET NEWNAME 切換檔案並恢復影像副本

skyin_1603發表於2016-11-07

透過恢復影像副本,簡單地修改資料檔名並把資料庫恢復回來,
操作起來簡單,比cp方式更省事。

----使用 SET NEWNAME 切換檔案:

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

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

Tablespace created.


--檢視錶空間:

SQL> select file_name from dba_data_files where tablespace_name='TS_XXF';

FILE_NAME

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

/home/oracle/oradata/ts_xxf_01.dbf


---透過RMAN切換資料檔案路徑

[oracle@enmo ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 7 10:56:01 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=338469376)


RMAN> run

2> {ALLOCATE CHANNEL c1 DEVICE TYPE DISK;

3> SQL "ALTER TABLESPACE ts_xxf OFFLINE IMMEDIATE";

4> SET NEWNAME FOR DATAFILE '/home/oracle/oradata/ts_xxf_01.dbf'

5>  TO '/u01/app/oracle/oradata/PROD/ts_xxf_01.dbf';

6> RESTORE TABLESPACE ts_xxf;

7> SWITCH DATAFILE ALL;

8> RECOVER TABLESPACE ts_xxf;

9> SQL "ALTER TABLESPACE ts_xxf ONLINE";

10> }

 #rman執行語句塊。

using target database control file instead of recovery catalog

allocated channel: c1

channel c1: SID=57 device type=DISK

sql statement: ALTER TABLESPACE ts_xxf OFFLINE IMMEDIATE

executing command: SET NEWNAME

Starting restore at 07-NOV-16

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

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

Finished restore at 07-NOV-16


datafile 6 switched to datafile copy

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

Starting recover at 07-NOV-16


starting media recovery

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

Finished recover at 07-NOV-16


sql statement: ALTER TABLESPACE ts_xxf ONLINE

released channel: c1

RMAN>

#完成。


---再次檢視TS_XXf表空間資料檔案的位置:

SQL> select file_name from dba_data_files where tablespace_name='TS_XXF';

FILE_NAME

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

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


---切換完畢後,刪除原來的資料檔案:

SQL> !ls /home/oracle/oradata/ts_xxf_01.dbf

/home/oracle/oradata/ts_xxf_01.dbf

SQL> !rm /home/oracle/oradata/ts_xxf_01.dbf

[oracle@enmo ~]$ ls

dirhome  homedir  mydoc  mydoc.zip  oradata

[oracle@enmo ~]$ cd oradata/

[oracle@enmo oradata]$ ls

[oracle@enmo oradata]$

#已經成功刪除舊的資料檔案。

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

相關文章