備份&恢復之四:非歸檔模式下的備份與恢復

mengzhaoliang發表於2008-05-07
備份&恢復之四:非歸檔模式下的備份與恢復

來自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  設定成非歸檔模式.
[oracle@mzl ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 7 18:24:26 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to an idle instance.

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> alter database noarchivelog;

Database altered.

SQL> alter database open;

Database altered.

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>


4 建立表插入資料
SQL> drop table test;

Table dropped.

SQL> create table test(a int);

Table created.

SQL> insert into test values(1);

1 row created.

SQL> select * from test;

         A
----------
         1

SQL> commit;

Commit complete.

5  檢視錶test在哪個表空間
SQL> select table_name,tablespace_name from dba_tables
  2  where table_name='TEST';

TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
TEST                           SYSTEM

原來在system表空間內


6   執行冷備份指令碼
[oracle@mzl BackupDatabase]$ pwd
/home/mzl/BackupDatabase
[oracle@mzl BackupDatabase]$ vi coldbak.sql
#rem script.:coldbak.sql
#rem creater:mengzhaoliang
#rem data:2008/2/4
#rem desc:offline full backup database
#enter database
$ORACLE_HOME/bin/sqlplus "/as sysdba" <#--shutdown database
shutdown immediate
#--Copy Data file
!cp /u01/app/oracle/oradata/orcl/*.dbf /home/mzl/BackupDatabase/
#--Copy Control file
!cp /u01/app/oracle/oradata/orcl/*.ctl /home/mzl/BackupDatabase/
--Copy Log file
!cp /u01/app/oracle/oradata/orcl/*.log /home/mzl/BackupDatabase/
#--startup database
startup
<[oracle@mzl BackupDatabase]$ ./coldbak.sql

7  繼續插入資料.
SQL> insert into test values(2);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test;

         A
----------
         1
         2

8  關閉資料庫,把system01.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 system01.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 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf'


其中alert_ORCL.log資訊為:
Wed May  7 18:51:17 2008
Errors in file /u01/app/oracle/admin/orcl/bdump/orcl_dbw0_3450.trc:
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.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的資訊為:
*** SESSION ID:(167.1) 2008-05-07 18:51:17.505
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.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
---------- ------- ------- ------------------------------ ---------- ---------
         1 ONLINE  ONLINE                                    1091429 07-MAY-08



10   把原來的冷備份資料複製過來
[oracle@mzl orcl]$ pwd
/u01/app/oracle/oradata/orcl
[oracle@mzl orcl]$ ls
control01.ctl  create.sql     perfstat.dbf  redo03.log   sysaux01.dbf
control02.ctl  example01.dbf  redo01.log    risenet.dbf  undotbs01.dbf
control03.ctl  Old            redo02.log    sqlnet.log   users01.dbf
[oracle@mzl orcl]$ cp /home/mzl/BackupDatabase/system01.dbf  .


11  執行recover操作,開啟資料庫
SQL> recover database;
Media recovery complete.

SQL> alter database open;

Database altered.

SQL> select * from test;

         A
----------
         1
         2





這裡可以發現,資料庫恢復成功,但在備份之後與崩潰之前的資料丟失了。
說明:
1、非歸檔模式下的恢復方案可選性很小,一般情況下只能有一種恢復方式,就是資料庫的冷備份的完全恢復,僅僅需要複製原來的備份,需要recover。
2、這種情況下的恢復,可以完全恢復到備份的點上,但是可能是丟失資料的,在備份之後與崩潰之前的資料將全部丟失。
3、不管毀壞了多少資料檔案或是聯機日誌或是控制檔案,都可以透過這個辦法恢復,因為這個恢復過程是Restore所有的冷備份檔案,而這個備份點上的所有檔案是一致的,與最新的資料庫沒有關係,就好比把資料庫又放到了一個以前的“點”上。
4、對於非歸檔模式下,最好的辦法就是採用OS的冷備份,建議不要用RMAN來作冷備份,效果不好,因為RMAN不備份聯機日誌,restore不能根本解決問題。
5、如果沒有備份聯機日誌,如RMAN的備份,就需要利用不完全恢復(until cancel)的方法來重新建立聯機日誌檔案

 

 

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

相關文章