Oracle數(shù)據(jù)庫基于用戶管理的控制文件的備份與恢復
在Oracle數(shù)據(jù)庫中,控制文件是非常重要的。它用于記錄和維護數(shù)據(jù)庫。當恢復數(shù)據(jù)庫時,服務器進程和后臺進程需要從控制文件中讀取各種備份相關的信息。如果控制文件損壞,則會導致這些備份信息的丟失。盡管使用多元化控制文件可以防止控制文件損壞,但因為控制文件的重要性,應該定期備份控制文件。當數(shù)據(jù)庫配置發(fā)生改變時,一定要備份控制文件。
涉及到數(shù)據(jù)庫配置改變的命令:
- alter database [add|drop] logfile
- alter database [add|drop] logfile member
- alter database [add|drop] logfile group
- alter database [noarchivelog|archivelog]
- alter database rename file
- create tablespace
- alter tablespace [add|rename] datafile
- alter tablespace [read write|read only]
- drop tablespace
控制文件的備份,三種方式
1)使用OS命令進行拷貝
1)open狀態(tài)下,使用alter database命令生成控制文件副本
2)open狀態(tài)下,使用alter database backup controlfile to trace命令將控制文件備份到跟蹤文件
控制文件的恢復,兩種方式
1)mount狀態(tài)下,使用RECOVER DATABASE USING BACKUP CONTROLFILE
2)mount狀態(tài)下,生成跟蹤文件并進行恢復
2--2示例:
- [oracle@localhost ~]$ rlsqlplus / as sysdba
- SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 8月 1 21:40:03 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- Connected to an idle instance.
- SQL> startup
- ORACLE instance started.
- Total System Global Area 528482304 bytes
- Fixed Size 1220360 bytes
- Variable Size 176161016 bytes
- Database Buffers 343932928 bytes
- Redo Buffers 7168000 bytes
- Database mounted.
- Database opened.
--open狀態(tài)下生成控制文件副本
- SQL> alter database backup controlfile to
- 2 '/oracle/10g/oracle/bakup/database/oralife.ctl';
- alter database backup controlfile to
- *
- ERROR at line 1:
- ORA-01580: error creating control backup file
- /oracle/10g/oracle/bakup/database/oralife.ctl
- ORA-27038: created file already exists
- Additional information: 1
- SQL> alter database backup controlfile to
- 2 '/oracle/10g/oracle/bakup/database/oralife.ctl' reuse; --reuse用于覆蓋原有控制文件副本
- Database altered.
--手動刪除所有控制文件模擬文件丟失
- SQL> ho rm /oracle/10g/oracle/product/10.2.0/oradata/oralife/*.ctl;
--使用evan登錄,并添加數(shù)據(jù)
- SQL> conn evan/evan
- Connected.
- SQL> select * from t_evan;
- TEXT
- --------------------------------------------------------------------------------
- oracle
- java
- spring
- hibernate
- hibernate
- SQL> insert into t_evan values('added');
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> conn / as sysdba
- Connected.
- SQL> shutdown immediate
- ORA-00210: cannot open the specified control file
- ORA-00202: control file: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl'
- ORA-27041: unable to open file
- Linux Error: 2: No such file or directory
- Additional information: 3
- SQL> shutdown abort
- ORACLE instance shut down.
--alter_oralife.log出現(xiàn)這樣的信息:
- Mon Aug 1 23:13:51 2011
- ORA-00202: control file: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl'
- ORA-27037: unable to obtain file status
- Linux Error: 2: No such file or directory
- Additional information: 3
--拷貝控制文件到目標路徑
- SQL>ho cp /oracle/10g/oracle/bakup/database/oralife.ctl /oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl
- SQL> alter system set control_files='/oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl' scope = spfile; --修改control_files參數(shù),指定可用的控制文件
- System altered.
- SQL> startup force mount
- ORACLE instance started.
- Total System Global Area 528482304 bytes
- Fixed Size 1220360 bytes
- Variable Size 138412280 bytes
- Database Buffers 381681664 bytes
- Redo Buffers 7168000 bytes
- Database mounted.
--生成trace文件
- SQL> alter database backup controlfile to trace noresetlogs;
- Database altered.
- SELECT c.VALUE || '/' || d.instance_name || '_ora_' || a.spid || '.trc' TRACE
- FROM v$process a, v$session b, v$parameter c, v$instance d
- WHERE a.addr = b.paddr
- AND b.audsid = USERENV ('sessionid')
- AND c.NAME = 'user_dump_dest';
- TRACE
- --------------------------------------------------------------------------------
- /oracle/10g/oracle/product/10.2.0/db_1/admin/oralife/udump/oralife_ora_4558.trc
- SQL> shutdown immediate
- ORA-01109: database not open
- Database dismounted.
- ORACLE instance shut down.
--打開trace文件,去掉注釋,在shutdown狀態(tài)下執(zhí)行腳本,創(chuàng)建控制文件
--用evan登錄驗證數(shù)據(jù)
- SQL> conn evan/evan
- Connected.
- SQL> select * from t_evan;
- TEXT
- --------------------------------------------------------------------------------
- oracle
- java
- spring
- hibernate
- hibernate
- added
- 6 rows selected.
可見數(shù)據(jù)沒有丟失。
- SQL> select name from v$controlfile;
- NAME
- --------------------------------------------------------------------------------
- /oracle/10g/oracle/product/10.2.0/oradata/oralife/control01.ctl
這時就需要重建多個控制文件了,以確保數(shù)據(jù)庫配置的安全性。
關于Oracle數(shù)據(jù)庫控制文件的備份與恢復就介紹到這里了,希望本次的介紹能夠帶給您一些收獲!
【編輯推薦】


2010-10-26 10:24:06




