備份之控制檔案備份

zhengbao_jun發表於2009-02-11

控制檔案的備份和恢復在資料庫的備份恢復過程中十分關鍵。


備份控制檔案的原則是:在資料庫物理結構發生變化後備份控制檔案。

備份控制檔案包括三種方法:

通過作業系統命令在資料庫關閉時對控制檔案進行COPY;

利用ALTER DATABASE BACKUP CONTROLFILE TO命令將控制檔案備份到二進位制檔案;

利用ALTER DATABASE BACKUP CONTROLFILE TO TRACE命令將重建控制檔案備份的指令碼備份到後臺trace檔案中。

Oracle推薦使用第二種方式來備份控制檔案。第一種方式備份的控制檔案,一般用於全庫一致性恢復。而第三種方式備份控制檔案會丟失歸檔日誌歷史等許多資訊。在重建控制檔案時,只讀表空間和離線的資料檔案的處理相對比較複雜。

第二種方式備份也是最簡單的方法,只需要執行下面的步驟:

SQL> ALTER DATABASE BACKUP CONTROLFILE TO 'F:ORACLEBACKUPTEST20060202CONTROL.BAK';

資料庫已更改。

採用第三種方式備份控制檔案:

SQL> SELECT TABLESPACE_NAME, STATUS FROM DBA_TABLESPACES;

TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
INDX READ ONLY
TOOLS ONLINE
USERS ONLINE
YANGTK ONLINE

已選擇7行。

SQL> SELECT NAME, STATUS FROM V$DATAFILE;

NAME STATUS
-------------------------------------------------- -------
F:ORACLEORADATATESTSYSTEM01.DBF SYSTEM
F:ORACLEORADATATESTUNDOTBS01.DBF ONLINE
F:ORACLEORADATATESTINDX01.DBF ONLINE
F:ORACLEORADATATESTTOOLS01.DBF ONLINE
F:ORACLEORADATATESTUSERS01.DBF RECOVER
F:ORACLEORADATATESTYANGTK01.DBF ONLINE

已選擇6行。

SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE;

資料庫已更改。

SQL> SELECT SPID FROM V$PROCESS
2 WHERE ADDR =
3 (
4 SELECT PADDR FROM V$SESSION
5 WHERE SID = (SELECT SID FROM V$MYSTAT WHERE ROWNUM = 1)
6 )
7 ;

SPID
------------
3308

開啟f:oracleadmintestudumptest_ora_3308.trc檔案:

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TEST" NORESETLOGS ARCHIVELOG
-- SET STANDBY TO MAXIMIZE PERFORMANCE
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 'F:ORACLEORADATATESTREDO01.LOG' SIZE 100M,
GROUP 2 'F:ORACLEORADATATESTREDO02.LOG' SIZE 100M,
GROUP 3 'F:ORACLEORADATATESTREDO03.LOG' SIZE 100M
-- STANDBY LOGFILE
DATAFILE
'F:ORACLEORADATATESTSYSTEM01.DBF',
'F:ORACLEORADATATESTUNDOTBS01.DBF',
'F:ORACLEORADATATESTTOOLS01.DBF',
'F:ORACLEORADATATESTUSERS01.DBF',
'F:ORACLEORADATATESTYANGTK01.DBF'
CHARACTER SET ZHS16GBK
;
# Take files offline to match current control file.
ALTER DATABASE DATAFILE 'F:ORACLEORADATATESTUSERS01.DBF' OFFLINE;
# Recovery is required if any of the datafiles are restored backups,
# or if the last shutdown was not normal or immediate.
RECOVER DATABASE
# All logs need archiving and a log switch is needed.
ALTER SYSTEM ARCHIVE LOG ALL;
# Database can now be opened normally.
ALTER DATABASE OPEN;
# Files in read-only tablespaces are now named.
ALTER DATABASE RENAME FILE 'MISSING00003'
TO 'F:ORACLEORADATATESTINDX01.DBF';
# Online the files in read-only tablespaces.
ALTER TABLESPACE "INDX" ONLINE;
# Commands to add tempfiles to temporary tablespaces.
# Online tempfiles have complete space information.
# Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE 'F:ORACLEORADATATESTTEMP01.DBF'
SIZE 41943040 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

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

相關文章