Backup And Recovery User's Guide-從RMAN開始-恢復表空間

LuiseDalian發表於2014-02-14

可以在資料庫開啟時在單獨的表空間上使用RESTORE TABLESPACERECOVER TABLESPACE命令。

此時,必須使需要恢復的表空間離線,還原和恢復表空間,然後再使表空間聯機。

如果不能還原資料檔案到新的位置,則使用RMANSET NEWNAME命令來指定新的檔名。

然後使用SWITCH DATAFILE ALL命令,等價於使用ALTER DATABASE RENAME FILE這個SQL命令來更新控制檔案反映新的檔名。

與使用者管理的介質恢復不同,不能將聯機表空間置於備份模式中。

與使用者管理的工具不同,RMAN不需要額外的日誌或備份模式,因為它知道資料塊的格式。

練習:在資料庫開啟時,恢復單個的表空間

# 1. 對資料庫進行備份

RMAN> backup database;

Starting backup at 12-JUL-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/TestDB12/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/TestDB12/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/TestDB12/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/TestDB12/undotbs01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/TestDB12/users01.dbf

channel ORA_DISK_1: starting piece 1 at 12-JUL-13

channel ORA_DISK_1: finished piece 1 at 12-JUL-13

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB12/backupset/2013_07_12/o1_mf_nnndf_TAG20130712T054632_8xzn3rgk_.bkp tag=TAG20130712T054632 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 12-JUL-13

channel ORA_DISK_1: finished piece 1 at 12-JUL-13

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB12/backupset/2013_07_12/o1_mf_ncsnf_TAG20130712T054632_8xzn5jod_.bkp tag=TAG20130712T054632 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 12-JUL-13

# 2. 刪除users表空間中emp表中的所有資料

sys@TESTDB12>delete  from scott.emp;

14 rows deleted.

# 3. 使表空間離線

RMAN> SQL 'ALTER TABLESPACE users OFFLINE';

sql statement: ALTER TABLESPACE users OFFLINE

# 4. 還原和恢復表空間(為資料檔案指定了新的名字)

RMAN> RUN

2> {

3>   SET NEWNAME FOR DATAFILE '/u01/app/oracle/oradata/TestDB12/users01.dbf'

4>    TO '/u01/app/oracle/oradata/TestDB12/users001.dbf';

5>   RESTORE TABLESPACE users;

6>   SWITCH DATAFILE ALL;  

7>   RECOVER TABLESPACE users;

8> }

executing command: SET NEWNAME

Starting restore at 12-JUL-13

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=20 device type=DISK

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 00004 to /u01/app/oracle/oradata/TestDB12/users001.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TESTDB12/backupset/2013_07_12/o1_mf_nnndf_TAG20130712T054632_8xzn3rgk_.bkp

channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TESTDB12/backupset/2013_07_12/o1_mf_nnndf_TAG20130712T054632_8xzn3rgk_.bkp tag=TAG20130712T054632

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished restore at 12-JUL-13

datafile 4 switched to datafile copy

input datafile copy RECID=3 STAMP=820561942 file name=/u01/app/oracle/oradata/TestDB12/users001.dbf

Starting recover at 12-JUL-13

using channel ORA_DISK_1

starting media recovery

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

Finished recover at 12-JUL-13

# 4. 使表空間聯機

MAN> sql 'alter tablespace users online';

sql statement: alter tablespace users online

# 5. 檢視錶空間的內容,資料已經被刪除了,說明已經恢了備份之後的操作。

 

可以使用RESTORE DATAFILERECOVER DATAFILE命令在資料檔案層次進行恢復。

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

相關文章