備份&恢復之五:歸檔模式下丟失或損壞一個資料檔案
備份&恢復之五:歸檔模式下丟失或損壞一個資料檔案
來自piner:
http://www.itpub.net/viewthread.php?tid=126320&extra=page%3D4%26amp%3Bfilter%3Ddigest
在自己機器測試成功
測試環境:
1 作業系統:Redhat Linux 5
[oracle@mzl proc]$ cat /proc/version
Linux version 2.6.18-8.el5 (brewbuilder@ls20-bc2-14.build.redhat.com) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:21 EST 2007
2 資料庫版本:Oracle10g
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
3 設定成歸檔模式.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Current log sequence 18
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Next log sequence to archive 18
Current log sequence 18
SQL>
4 建立表插入資料
SQL> drop table test;
Table dropped.
SQL> create table test(a int) tablespace users;
Table created.
SQL> insert into test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
5 檢視錶test在哪個表空間
SQL> select table_name,tablespace_name from dba_tables
2 where table_name='TEST';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
TEST USERS
在users表空間內
6 執行熱備份指令碼
[oracle@mzl BackupDatabase]$ pwd
/home/mzl/BackupDatabase
[oracle@mzl BackupDatabase]$ vi hotbak.sql
#rem script.:hotbak.sql
#rem creater:mengzhaoliang
#rem data:2008/2/4
#rem desc:backup all database datafile in archive
#enter database
$ORACLE_HOME/bin/sqlplus "/as sysdba" <alter system archive log current;
#start
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/system01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/undotbs01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/users01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/sysaux01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/example01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
#backup control file
#binary
alter database backup controlfile to '/home/mzl/BackupDatabase/controlbinarybackup';
#ascii
alter database backup controlfile to trace;
alter system archive log current;
<
[oracle@mzl BackupDatabase]$ ./hotbak.sql
7 繼續插入資料.
SQL> insert into test values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
2
8 關閉資料庫,把users01.dbf資料檔案移出
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@mzl orcl]$ pwd
/u01/app/oracle/oradata/orcl
[oracle@mzl orcl]$ ls
control01.ctl create.sql redo01.log risenet.dbf system01.dbf
control02.ctl example01.dbf redo02.log sqlnet.log undotbs01.dbf
control03.ctl perfstat.dbf redo03.log sysaux01.dbf users01.dbf
[oracle@mzl orcl]$ mkdir Old
[oracle@mzl orcl]$ mv users01.dbf Old
9 啟動資料庫
SQL> startup
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
其中alert_ORCL.log資訊為:
ALTER DATABASE OPEN
Wed May 7 19:42:59 2008
Errors in file /u01/app/oracle/admin/orcl/bdump/orcl_dbw0_3972.trc:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-1157 signalled during: ALTER DATABASE OPEN...
其中orcl_dbw0_3450.trc的資訊為:
*** SERVICE NAME:() 2008-05-07 19:42:59.118
*** SESSION ID:(167.1) 2008-05-07 19:42:59.118
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
檢視哪些檔案需要恢復:
SQL> select * from v$recover_file;
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- ------------------------------ ---------- ---------
4 ONLINE ONLINE FILE NOT FOUND 0
10 離線資料檔案
SQL> alter database datafile 4 offline drop;
Database altered.
11 開啟資料庫,複製備份回來(restore),恢復(recover)該資料檔案,並聯機
SQL> alter database open;
Database altered.
[oracle@mzl orcl]$ pwd
/u01/app/oracle/oradata/orcl
[oracle@mzl orcl]$ cp /home/mzl/BackupDatabase/users01.dbf .
SQL> recover datafile 4;
Media recovery complete.
SQL> alter database datafile 4 online;
Database altered.
SQL> select * from test;
A
----------
1
2
說明:
1、採用熱備份,需要執行在歸檔模式下,可以實現資料庫的完全恢復,也就是說,從備份後到資料庫崩潰時的資料都不會丟失。
2、可以採用全備份資料庫的方式備份,對於特殊情況,也可以只備份特定的資料檔案,如只備份使用者表空間(一般情況下對於某些寫特別頻繁的資料檔案,可以單獨加大備份頻率)
3、如果在恢復過程中,發現損壞的是多個資料檔案,即可以採用一個一個資料檔案的恢復方法(第5步中需要對資料檔案一一離線,第6步中需要對資料檔案分別恢復),也可以採用整個資料庫的恢復方法。
4、如果是系統表空間的損壞,不能採用此方法
來自piner:
http://www.itpub.net/viewthread.php?tid=126320&extra=page%3D4%26amp%3Bfilter%3Ddigest
在自己機器測試成功
測試環境:
1 作業系統:Redhat Linux 5
[oracle@mzl proc]$ cat /proc/version
Linux version 2.6.18-8.el5 (brewbuilder@ls20-bc2-14.build.redhat.com) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:21 EST 2007
2 資料庫版本:Oracle10g
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
3 設定成歸檔模式.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Current log sequence 18
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Next log sequence to archive 18
Current log sequence 18
SQL>
4 建立表插入資料
SQL> drop table test;
Table dropped.
SQL> create table test(a int) tablespace users;
Table created.
SQL> insert into test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
5 檢視錶test在哪個表空間
SQL> select table_name,tablespace_name from dba_tables
2 where table_name='TEST';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
TEST USERS
在users表空間內
6 執行熱備份指令碼
[oracle@mzl BackupDatabase]$ pwd
/home/mzl/BackupDatabase
[oracle@mzl BackupDatabase]$ vi hotbak.sql
#rem script.:hotbak.sql
#rem creater:mengzhaoliang
#rem data:2008/2/4
#rem desc:backup all database datafile in archive
#enter database
$ORACLE_HOME/bin/sqlplus "/as sysdba" <
#start
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/system01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/undotbs01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/users01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/sysaux01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/example01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
#backup control file
#binary
alter database backup controlfile to '/home/mzl/BackupDatabase/controlbinarybackup';
#ascii
alter database backup controlfile to trace;
alter system archive log current;
<
[oracle@mzl BackupDatabase]$ ./hotbak.sql
7 繼續插入資料.
SQL> insert into test values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
2
8 關閉資料庫,把users01.dbf資料檔案移出
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@mzl orcl]$ pwd
/u01/app/oracle/oradata/orcl
[oracle@mzl orcl]$ ls
control01.ctl create.sql redo01.log risenet.dbf system01.dbf
control02.ctl example01.dbf redo02.log sqlnet.log undotbs01.dbf
control03.ctl perfstat.dbf redo03.log sysaux01.dbf users01.dbf
[oracle@mzl orcl]$ mkdir Old
[oracle@mzl orcl]$ mv users01.dbf Old
9 啟動資料庫
SQL> startup
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
其中alert_ORCL.log資訊為:
ALTER DATABASE OPEN
Wed May 7 19:42:59 2008
Errors in file /u01/app/oracle/admin/orcl/bdump/orcl_dbw0_3972.trc:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-1157 signalled during: ALTER DATABASE OPEN...
其中orcl_dbw0_3450.trc的資訊為:
*** SERVICE NAME:() 2008-05-07 19:42:59.118
*** SESSION ID:(167.1) 2008-05-07 19:42:59.118
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
檢視哪些檔案需要恢復:
SQL> select * from v$recover_file;
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- ------------------------------ ---------- ---------
4 ONLINE ONLINE FILE NOT FOUND 0
10 離線資料檔案
SQL> alter database datafile 4 offline drop;
Database altered.
11 開啟資料庫,複製備份回來(restore),恢復(recover)該資料檔案,並聯機
SQL> alter database open;
Database altered.
[oracle@mzl orcl]$ pwd
/u01/app/oracle/oradata/orcl
[oracle@mzl orcl]$ cp /home/mzl/BackupDatabase/users01.dbf .
SQL> recover datafile 4;
Media recovery complete.
SQL> alter database datafile 4 online;
Database altered.
SQL> select * from test;
A
----------
1
2
說明:
1、採用熱備份,需要執行在歸檔模式下,可以實現資料庫的完全恢復,也就是說,從備份後到資料庫崩潰時的資料都不會丟失。
2、可以採用全備份資料庫的方式備份,對於特殊情況,也可以只備份特定的資料檔案,如只備份使用者表空間(一般情況下對於某些寫特別頻繁的資料檔案,可以單獨加大備份頻率)
3、如果在恢復過程中,發現損壞的是多個資料檔案,即可以採用一個一個資料檔案的恢復方法(第5步中需要對資料檔案一一離線,第6步中需要對資料檔案分別恢復),也可以採用整個資料庫的恢復方法。
4、如果是系統表空間的損壞,不能採用此方法
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12778571/viewspace-263079/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 備份與恢復--資料檔案損壞或丟失
- 備份&恢復之八:RMAN備份歸檔模式下損壞(丟失)多個資料檔案,進行整個資料庫的恢復模式資料庫
- rman 恢復---歸檔丟失and資料檔案損壞
- 【備份恢復】非歸檔模式下丟失任意資料檔案 恢復操作模式
- 歸檔模式無備份丟失資料檔案後恢復模式
- 歸檔模式有備份丟失資料檔案後恢復模式
- rman恢復--歸檔模式有備份,丟失資料檔案的恢復模式
- rman恢復--歸檔模式無備份,丟失資料檔案的恢復模式
- 【備份恢復】歸檔模式下丟失系統關鍵資料檔案 利用RMAN備份恢復模式
- RMAN資料庫恢復 之歸檔模式有(無)備份-丟失資料檔案的恢復資料庫模式
- 資料檔案丟失損壞的恢復--
- 歸檔模式下資料檔案丟失的恢復模式
- 備份恢復之資料檔案丟失
- 歸檔模式下丟失普通資料檔案並恢復模式
- 恢復案例:歸檔模式下丟失全部資料檔案的恢復模式
- 【備份恢復】 丟失一個控制檔案 之恢復操作
- 非歸檔無備份下控制檔案丟失的恢復
- 【備份恢復】恢復 丟失已歸檔重做日誌檔案
- 沒備份,歸檔日誌存在,丟失資料檔案的恢復
- rman備份但丟失一個資料檔案,但有歸檔備份
- 備份&恢復之十二:損壞單個控制檔案
- 磁碟損壞導致資料檔案丟失的恢復
- 歸檔模式有備份丟失控制檔案和資料檔案後恢復模式
- undo檔案丟失或損壞
- REDO日誌損壞,非歸檔模式資料檔案恢復模式
- piner的歸檔模式下丟失或損壞一個資料檔案,在linux+oracle10g下測試成功!模式LinuxOracle
- REDO檔案丟失或者損壞的恢復
- 資料檔案損壞、丟失
- 備份與恢復--重建控制檔案後資料檔案損壞的恢復
- Oracle重做日誌檔案損壞或丟失後的恢復Oracle
- Oracle備份與恢復【丟失資料檔案的恢復】Oracle
- 備份&恢復之十三:損壞全部控制檔案
- RMAN_部分資料檔案丟失或者損壞的恢復
- Oracle RMAN 不完全恢復(只有資料檔案備份,丟失歸檔日誌備份)Oracle
- 在歸檔模式下丟失日誌檔案的恢復模式
- Oracle不同檔案丟失/損壞的恢復方法Oracle
- 丟失已歸檔日誌檔案下恢復資料庫資料庫
- oracle控制檔案的損壞或完全丟失的恢復辦法Oracle