備份控制檔案

楊奇龍發表於2010-05-08

控制檔案用於記錄和維護資料庫,當恢復資料庫時,伺服器程式和後臺程式需要從控制檔案中讀取各種與備份相關的資訊。如果控制檔案損壞,則會導致這些資訊丟失。儘管多元化的控制檔案可以防止控制檔案損壞,但因控制檔案的重要性,所以應當定期的備份控制檔案。當資料庫配置發生變化時,一定要備份控制檔案。

涉及到改變資料庫配置的命令一般以 alter database 、ceate tablespace,alter tablespace ,drop tablespace 等命令。

第一 建立控制檔案的副本。

SQL> alter database backup controlfile
  2  to 'F:\lib\control.ctl' reuse;

----resue 是當控制檔案副本已經存在時,可以覆蓋以前的副本。若不存在副本,則可以省去resue

資料庫已更改。

     執行該語句時,oracle會將當前的控制檔案的資訊全部存放到控制檔案的副本中,透過控制檔案副本,一 可以執行基於控制檔案的不完全恢復,二是可以生成控制檔案的文字跟蹤檔案。注意:在open狀態時,控制檔案只能用alter databae命令生成,而不能用os命令直接複製

二 備份到跟蹤檔案。

SQL> alter database backup controlfile to trace;

資料庫已更改。此命令將控制檔案中記錄的資訊備份到跟蹤檔案,然後可以使用跟蹤檔案建立控制檔案。

1) 確認跟蹤檔案的位置。

SQL> show parameter user_dump_dest

NAME                                 TYPE        VALUE                         
------------------------------------ ----------- ------------------------------
user_dump_dest                       string      f:\app\yang\diag\rdbms\oracl\o
                                                 racl\trace                    

2)確定跟蹤檔案的名稱。跟著檔案的名稱_ora_.TRC。其中sid為例程名即 oracle_SID的名稱,spid 是伺服器程式所對應作業系統的程式號。

SQL> select a.spid from v$process a,v$session b
  2  where a.addr=b.paddr and b.username='SYS';

SPID                                                                           
------------------------                                                       
572                                                                            

3)檢視跟蹤檔案。oracl_ora_572 在這裡我沒有把註釋去掉,以方便大家研究。

當將跟蹤檔案的註釋內容和說明資訊去掉,剩餘部分就可以用來重新建立控制檔案的全部內容。當控制檔案出現介質損壞時,透過執行這部分語句就可以恢復損壞的控制檔案了。

Trace file f:\app\yang\diag\rdbms\oracl\oracl\trace\oracl_ora_572.trc
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Windows XP Version V5.1 Service Pack 3
CPU                 : 2 - type 586, 2 Physical Cores
Process Affinity    : 0x00000000
Memory (Avail/Total): Ph:902M/2046M, Ph+PgF:2348M/3938M, VA:1246M/2047M
Instance name: oracl
Redo thread mounted by this instance: 1
Oracle process number: 31
Windows thread id: 572, image: ORACLE.EXE (SHAD)


*** 2010-05-08 21:43:10.765
*** SESSION ID:(128.147) 2010-05-08 21:43:10.765
*** CLIENT ID:() 2010-05-08 21:43:10.765
*** SERVICE NAME:(SYS$USERS) 2010-05-08 21:43:10.765
*** MODULE NAME:(sqlplus.exe) 2010-05-08 21:43:10.765
*** ACTION NAME:() 2010-05-08 21:43:10.765
 
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%s_%t_%r.log
--
-- DB_UNIQUE_NAME="oracl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=5
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=%ORACLE_HOME%\RDBMS
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_2='LOCATION=f:\app\yang\archive2'
-- LOG_ARCHIVE_DEST_2='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_2='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_2='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_2='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_2='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_2=ENABLE
--
-- LOG_ARCHIVE_DEST_1='LOCATION=f:\app\yang\archive1'
-- LOG_ARCHIVE_DEST_1='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE
--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script. file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
--     Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORACL" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 'F:\APP\YANG\ORADATA\ORACL\REDO01.LOG'  SIZE 50M,
  GROUP 2 'F:\APP\YANG\ORADATA\ORACL\REDO02.LOG'  SIZE 50M,
  GROUP 3 'F:\APP\YANG\ORADATA\ORACL\REDO03.LOG'  SIZE 50M

-- STANDBY LOGFILE
DATAFILE
  'F:\APP\YANG\ORADATA\ORACL\SYSTEM01.DBF',
  'F:\APP\YANG\ORADATA\ORACL\SYSAUX01.DBF',
  'F:\APP\YANG\ORADATA\ORACL\UNDOTBS01.DBF',
  'F:\APP\YANG\ORADATA\ORACL\USERS01.DBF',
  'F:\APP\YANG\ORADATA\ORACL\EXAMPLE01.DBF'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE 'F:\APP\YANG\ARCHIVE2\1_1_636026939.LOG';
-- ALTER DATABASE REGISTER LOGFILE 'F:\APP\YANG\ARCHIVE2\1_1_715961434.LOG';
-- 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;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE 'F:\APP\YANG\ORADATA\ORACL\TEMP01.DBF'
     SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.

好了,如何備份控制檔案到此結束。至於具體的基於控制檔案的不完全恢復,我會在後續的文章中給出具體的步驟。。。。

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

相關文章