gdufo

           

          Rman全備份不完全恢復數據庫

          數據庫今天宕機了,數據文件和控制文件在一個磁盤,全部損壞,redo文件和

           

          歸檔日志在兩外一個磁盤,完好無損,只有兩天前的rman全備份。經過30分鐘的奮戰,數據全部恢復。

           

          模擬環境,具體恢復如下:

           

          1:首先用rman全備份數據庫數據(模擬兩天前的rman全備份)

           

          [oracle@www oracle]$ rman target /

           

          Recovery Manager: Release 9.2.0.8.0 - Production

           

          Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

           

          connected to target database: EXITGOGO (DBID=267967027)

           


          RMAN> backup database;

           

          Starting backup at 23-11-06

           

          using target database controlfile instead of recovery catalog

           

          allocated channel: ORA_DISK_1

           

          channel ORA_DISK_1: sid=11 devtype=DISK

           

          channel ORA_DISK_1: starting full datafile backupset

           

          channel ORA_DISK_1: specifying datafile(s) in backupset

           

          input datafile fno=00001 name=/free/oracle/oradata/exitgogo/system01.dbf

           

          input datafile fno=00002 name=/free/oracle/oradata/exitgogo/undotbs01.dbf

           

          input datafile fno=00003 name=/free/oracle/oradata/exitgogo/users01.dbf

           

          input datafile fno=00006 name=/free/oracle/oradata/exitgogo/pub.dbf

           

          input datafile fno=00004 name=/free/oracle/oradata/exitgogo/tools01.dbf

           

          input datafile fno=00005 name=/free/oracle/oradata/exitgogo/indx01.dbf

           

          channel ORA_DISK_1: starting piece 1 at 23-11-06

           

          channel ORA_DISK_1: finished piece 1 at 23-11-06

           

          piece handle=/free/oracle/product/9.2.0.8/dbs/03i34pja_1_1 comment=NONE

           

          channel ORA_DISK_1: backup set complete, elapsed time: 00:01:06

           

          Finished backup at 23-11-06

           


          Starting Control File Autobackup at 23-11-06

           

          piece handle=/free/oracle/orabak/c-267967027-20061123-01 comment=NONE

           

          Finished Control File Autobackup at 23-11-06

           


          RMAN> show all;

           

          RMAN configuration parameters are:

           

          CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

           

          CONFIGURE BACKUP OPTIMIZATION ON;

           

          CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

           

          CONFIGURE CONTROLFILE AUTOBACKUP ON;

           

          CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/free/oracle/orabak/%F';

           

          CONFIGURE DEVICE TYPE DISK PARALLELISM 1;

           

          CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

           

          CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

           

          RMAN configuration has no stored or default parameters

           

          CONFIGURE MAXSETSIZE TO UNLIMITED; # default

           

          CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/free/oracle/product/9.2.0.8/dbs/snapcf_exitgogo.f'; # default

           


          RMAN>quit

           

          2:創建一個新的表空間,然后添加測試數據(模擬兩天之間數據庫的變化)

           


          創建了一個新的表空間pub,然后創建了用戶pub。

           

          [oracle@www oracle]$ sqlplus  pub/pub

           

          SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11 23 17:37:28 2006

           

          Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

           

          Connected to:

           

          Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

           

          With the Partitioning and Oracle Data Mining options

           

          JServer Release 9.2.0.8.0 – Production

           

          添加一點測試數據:

           

          SQL> create table gaojf1 as  select * from all_objects;

           

          Table created.

           

          SQL> insert into gaojf1 select * from gaojf1;

           

          5884 rows created.

           

          SQL> /

           

          11768 rows created.

           

          SQL> /

           

          。。。。。。。。。。。

           

          188288 rows created.

           


          SQL> /

           

          376576 rows created.

           

          SQL> commit;

           

          Commit complete.

           

          SQL> quit

           

          Disconnected from Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

           

          With the Partitioning and Oracle Data Mining options

           

          JServer Release 9.2.0.8.0 - Production

           


          3:刪除所有數據文件和控制文件(模擬數據庫宕機)

           

          [oracle@www exitgogo]$ls -sh

           

          total 886M

           

          3.5M control01.ctl   33M indx01.dbf   51M redo02.log    136K temp01.dbf     129M users01.dbf 3.5M control02.ctl  101M pub.dbf      51M redo03.log     65M tools01.dbf 3.5M control03.ctl   51M redo01.log  201M system01.dbf  201M undotbs01.dbf

           

          [oracle@www exitgogo]$  rm -rf ./*.dbf ./*.ctl

           

          [oracle@www exitgogo]$ ls

           

          redo01.log  redo02.log  redo03.log

           


          4:恢復開始:

           

          [oracle@www exitgogo]$ rman target /

           

          Recovery Manager: Release 9.2.0.8.0 - Production

           

          Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

           

          connected to target database (not started)

           

          RMAN> startup nomount

           

          Oracle instance started

           

          Total System Global Area     235999648 bytes

           

          Fixed Size                      450976 bytes

           

          Variable Size                201326592 bytes

           

          Database Buffers              33554432 bytes

           

          Redo Buffers                    667648 bytes

           


          首先從原來的全備份中恢復控制文件

           

          RMAN>

           

          restore controlfile from '/free/oracle/orabak/c-267967027-20061123-01';

           


          Starting restore at 23-11-06

           

          using target database controlfile instead of recovery catalog

           

          allocated channel: ORA_DISK_1

           

          channel ORA_DISK_1: sid=13 devtype=DISK

           

          channel ORA_DISK_1: restoring controlfile

           

          channel ORA_DISK_1: restore complete

           

          replicating controlfile

           

          input filename=/free/oracle/oradata/exitgogo/control01.ctl

           

          output filename=/free/oracle/oradata/exitgogo/control02.ctl

           

          output filename=/free/oracle/oradata/exitgogo/control03.ctl

           

          Finished restore at 23-11-06

           

          RMAN> alter database mount;

           

          database mounted

           

          RMAN> list backup;

           

          List of Backup Sets

           

          ===================

           


          BS Key  Type LV Size       Device Type Elapsed Time Completion Time

           

          ------- ---- -- ---------- ----------- ------------ ---------------

           

          1       Full    3M         DISK        00:00:00     23-11-06    

           

                  BP Key: 1   Status: AVAILABLE   Tag:

           

                  Piece Name: /free/oracle/orabak/c-267967027-20061123-01

           

            Controlfile Included: Ckp SCN: 73561        Ckp time: 23-11-06

           


          BS Key  Type LV Size       Device Type Elapsed Time Completion Time

           

          ------- ---- -- ---------- ----------- ------------ ---------------

           

          2       Full    223M       DISK        00:00:57     23-11-06    

           

                  BP Key: 2   Status: AVAILABLE   Tag: TAG20061123T173423

           

                  Piece Name: /free/oracle/product/9.2.0.8/dbs/03i34p90_1_1

           

            List of Datafiles in backup set 2

           

            File LV Type Ckp SCN    Ckp Time   Name

           

            ---- -- ---- ---------- ---------- ----

           

            1       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/system01.dbf

           

            2       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/undotbs01.dbf

           

            3       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/users01.dbf

           

            4       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/tools01.dbf

           

            5       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/indx01.dbf

           



          還原數據文件

           

          RMAN> restore database;

           

          Starting restore at 23-11-06

           


          using channel ORA_DISK_1

           

          channel ORA_DISK_1: starting datafile backupset restore

           

          channel ORA_DISK_1: specifying datafile(s) to restore from backup set

           

          restoring datafile 00001 to /free/oracle/oradata/exitgogo/system01.dbf

           

          restoring datafile 00002 to /free/oracle/oradata/exitgogo/undotbs01.dbf

           

          restoring datafile 00003 to /free/oracle/oradata/exitgogo/users01.dbf

           

          restoring datafile 00004 to /free/oracle/oradata/exitgogo/tools01.dbf

           

          restoring datafile 00005 to /free/oracle/oradata/exitgogo/indx01.dbf

           

          channel ORA_DISK_1: restored backup piece 1

           

          piece handle=/free/oracle/product/9.2.0.8/dbs/03i34p90_1_1 tag=TAG20061123T173423 params=NULL

           

          channel ORA_DISK_1: restore complete

           

          Finished restore at 23-11-06

           

          RMAN> quit

           


          下面進入sqlplus進行不完全恢復

           


          [oracle@www exitgogo]$ sqlplus  "/as sysdba"

           


          SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11 23 17:51:07 2006

           

          Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

           

          Connected to:

           

          Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

           

          With the Partitioning and Oracle Data Mining options

           

          JServer Release 9.2.0.8.0 - Production

           

          SQL> select name from v$datafile;

           

          NAME

           

          ------------------------------------------------------------------------------

           

          /free/oracle/oradata/exitgogo/system01.dbf

           

          /free/oracle/oradata/exitgogo/undotbs01.dbf

           

          /free/oracle/oradata/exitgogo/users01.dbf

           

          /free/oracle/oradata/exitgogo/tools01.dbf

           

          /free/oracle/oradata/exitgogo/indx01.dbf

           


          可以看到,由于rman的全備份早于創建pub表空間,因此restore恢復中沒有記錄pub表空間的信息,但是由于redo file中還記錄了pub表空間創建的信息,因此,先recover試試!

           


          SQL> recover database using backup controlfile;

           

          ORA-00279: change 73688 generated at 11/23/2006 17:34:24 needed for thread 1

           

          ORA-00289: suggestion :

           

          /free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000008.ARC

           

          ORA-00280: change 73688 for thread 1 is in sequence #8

           

          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

           

          auto

           

          ORA-00283: recovery session canceled due to errors

           

          ORA-01244: unnamed datafile(s) added to controlfile by media recovery

           

          ORA-01110: data file 6: '/free/oracle/oradata/exitgogo/pub.dbf'

           

          ORA-01112: media recovery not started

           


          可以看到,在恢復了一個歸檔日志以后,oracle認出了pub表空間,同時提示了ORA-01244 錯誤,繼續往下看:

           

           

           

          SQL> select name from v$datafile;

           

          NAME

           

          ------------------------------------------------------------------------------

           

          /free/oracle/oradata/exitgogo/system01.dbf

           

          /free/oracle/oradata/exitgogo/undotbs01.dbf

           

          /free/oracle/oradata/exitgogo/users01.dbf

           

          /free/oracle/oradata/exitgogo/tools01.dbf

           

          /free/oracle/oradata/exitgogo/indx01.dbf

           

          /free/oracle/product/9.2.0.8/dbs/UNNAMED00006

           

           

          6 rows selected.

           

           

          可以看到,oracle中莫名的多出了一個文件UNNAMED00006,

           

          IXDBA.NET社區論壇

          出現這個文件的原因是由于redo file中記錄了pub的信息,在通過recover恢復后,系統也認到了有pub這個表空間的存在,但是由于控制文件中沒有記錄這個文件的信息,所以oracle拋了一個錯誤,說發現一個沒有命名的文件,然后oracle系統本身給這個文件做了一個命名。

           

           

          可以通過下面的方式把pub表空間數據文件移動到合適的位置。

           

           

          SQL>

           

          alter database create datafile 6 as '/free/oracle/oradata/exitgogo/pub.dbf';

           

          Database altered.

           

          SQL> col name format a40

           

          SQL>  select file#,name from v$datafile;

           

           

               FILE# NAME

           

          ---------- ----------------------------------------

           

                   1 /free/oracle/oradata/exitgogo/system01.d bf

           

                   2 /free/oracle/oradata/exitgogo/undotbs01.dbf

           

                   3 /free/oracle/oradata/exitgogo/users01.dbf

           

                   4 /free/oracle/oradata/exitgogo/tools01.dbf

           

               FILE# NAME

           

          ---------- ----------------------------------------

           

                   5 /free/oracle/oradata/exitgogo/indx01.dbf

           

                   6 /free/oracle/oradata/exitgogo/pub.dbf

           

          6 rows selected.

           

           

          繼續恢復:

           

          SQL> recover database using backup controlfile;

           

          ORA-00279: change 73805 generated at 11/23/2006 17:37:18 needed for thread 1

           

          ORA-00289: suggestion :

           

          /free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000008.ARC

           

          ORA-00280: change 73805 for thread 1 is in sequence #8

           

          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

           

          auto

           

          ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

           

          ORA-00289: suggestion :

           

          /free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

           

          ORA-00280: change 74363 for thread 1 is in sequence #9

           

          ORA-00278: log file

           

          '/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000008.ARC' no longer

           

          needed for this recovery

           

           

          ORA-00308: cannot open archived log

           

          '/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC'

           

          ORA-27037: unable to obtain file status

           

          Linux Error: 2: No such file or directory

           

          Additional information: 3

           

          由于我的歸檔沒有T0001S0000000009了,所以可能需要redo file了

           

          SQL> recover database using backup controlfile;

           

          ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

           

          ORA-00289: suggestion :

           

          /free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

           

          ORA-00280: change 74363 for thread 1 is in sequence #9

           

          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

           

          /free/oracle/oradata/exitgogo/redo01.log

           

          ORA-00310: archived log contains sequence 7; sequence 9 required

           

          ORA-00334: archived log: '/free/oracle/oradata/exitgogo/redo01.log'

           

           

          SQL> recover database using backup controlfile;

           

          ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

           

          ORA-00289: suggestion :

           

          /free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

           

          ORA-00280: change 74363 for thread 1 is in sequence #9

           

          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

           

          /free/oracle/oradata/exitgogo/redo02.log

           

          ORA-00310: archived log contains sequence 8; sequence 9 required

           

          ORA-00334: archived log: '/free/oracle/oradata/exitgogo/redo02.log'

           

           

          SQL> recover database using backup controlfile;

           

          ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

           

          ORA-00289: suggestion :

           

          /free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

           

          ORA-00280: change 74363 for thread 1 is in sequence #9

           

          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

           

          /free/oracle/oradata/exitgogo/redo03.log

           

          Log applied.

           

          Media recovery complete.

           

          可以看到,新建的pub表空間的數據信息在redo03.log中存在,這是因為我的測試數據量很小的原因。如果從rman全備份后到系統宕機這段時間數據量很大的話,可能有很多的歸檔信息需要恢復,同時redo file也是不可少的。

           

          SQL> alter database open resetlogs;

           

          alter database open resetlogs

           

          *

           

          ERROR at line 1:

           

          ORA-01153: an incompatible media recovery is active

           

          SQL> quit

           

          Disconnected from Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

           

          With the Partitioning and Oracle Data Mining options

           

          JServer Release 9.2.0.8.0 - Production

           

          [oracle@www exitgogo]$ sqlplus  "/as sysdba"

           

          SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11 23 18:02:00 2006

           

          Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

           

          Connected to:

           

          Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

           

          With the Partitioning and Oracle Data Mining options

           

          JServer Release 9.2.0.8.0 - Production

           

          SQL> alter database open resetlogs;

           

          Database altered.

           

          SQL> conn pub/pub

           

          Connected.

           

          SQL> select count(*) from gaojf1;

           

            COUNT(*)

           

          ----------

           

              753152

           

          SQL>

           

          可以看到,數據完全恢復,

           

           

          這樣恢復完成后,馬上又做了一個全庫的rman備份。

          posted on 2009-12-01 09:58 gdufo 閱讀(1469) 評論(0)  編輯  收藏 所屬分類: Database (oracle, sqlser,MYSQL)

          導航

          統計

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          Hibernate

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 江山市| 永泰县| 南阳市| 白水县| 绥中县| 平武县| 嫩江县| 新泰市| 竹山县| 广汉市| 阿城市| 青州市| 定西市| 青铜峡市| 阿拉善右旗| 天门市| 旌德县| 桃江县| 沙雅县| 荥阳市| 凤冈县| 阿城市| 莲花县| 六盘水市| 准格尔旗| 金湖县| 潼南县| 长宁县| 金堂县| 长子县| 辉南县| 扶绥县| 镇原县| 花莲县| 泾源县| 蒙自县| 齐河县| 海林市| 甘泉县| 广汉市| 会昌县|