Decode360's Blog

          業(yè)精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
            397 隨筆 :: 33 文章 :: 29 評論 :: 0 Trackbacks
          <2008年9月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          公告

          話到七分,酒至微醺,筆墨疏宕,言詞婉約,古樸殘破,含蓄醞籍,就是不完而美之最高境界。

          常用鏈接

          留言簿(13)

          隨筆分類(397)

          隨筆檔案(397)

          文章分類(33)

          新聞分類(15)

          收藏夾(74)

          Blog_List

          IT_Web

          My_Link

          最新隨筆

          最新評論

          RMAN學(xué)習(xí)筆記05——恢復(fù)
          ?
          ?
          ??? 終于又到了關(guān)鍵部分了,RMAN當(dāng)然就是以備份和恢復(fù)最為關(guān)鍵,所以RMAN的恢復(fù)是非常重要的學(xué)習(xí)部分。在恢復(fù)的時(shí)候,關(guān)鍵不是語句的格式,而是一些相關(guān)的原理一定要搞清楚,各個(gè)層級的關(guān)系是怎么樣的,相對于恢復(fù)的文件、時(shí)間點(diǎn)又是怎么樣的,如何在catalog中進(jìn)行記錄,都是需要熟悉了解的概念。下面看一下:
          ?
          ?
          一、恢復(fù)類型:
          ?
          ??? 使用RMAN做的備份只能通過RMAN進(jìn)行恢復(fù),恢復(fù)分為兩種:數(shù)據(jù)庫修復(fù)(Restore)數(shù)據(jù)庫恢復(fù)(Recover)
          ?
          ??? Restore:指用備份文件來替換已損壞的數(shù)據(jù)庫文件。操作時(shí)會利用恢復(fù)目錄來獲取備份信息(如果沒有恢復(fù)目錄則使用數(shù)據(jù)庫的控制文件)
          ??? Recover:利用重做日志或增量備份來重建丟失的數(shù)據(jù)。
          ?
          ?
          二、恢復(fù)數(shù)據(jù)庫:
          ?
          ??? 恢復(fù)數(shù)據(jù)庫必須使數(shù)據(jù)庫處于加載狀態(tài):
          ?
          ??? RMAN> Shutdown immediate;
          ??? RMAN> Startup mount;
          ?
          ??? RMAN> Restore database;
          ??? RMAN> Recover database delete archivelogs skip tablespace temp;
          ?
          ??? RMAN> Alter database open;
          ?
          ??? 注意:
          ??? 1、skip指跳過某文件類型
          ??? 2、若數(shù)據(jù)庫是非歸檔模式,則必須使用RMAN> Alter database open resetlogs
          ?
          ?
          三、恢復(fù)表空間:
          ?
          ??? RMAN> Shutdown immediate;
          ??? RMAN> Startup mount;
          ??? RMAN> SQL 'Alter tablespace users offline immediate';
          ?
          ??? RMAN> Restore tablespace users;
          ??? RMAN> Recover tablespace users;
          ?
          ??? RMAN> SQL 'Alter tablespace users online' ;
          ??? RMAN> Alter database open;
          ?
          ?
          四、恢復(fù)數(shù)據(jù)文件:
          ?
          ??? RMAN> Shutdown immediate;
          ??? RMAN> Startup mount;
          ??? RMAN> SQL 'Alter tablespace datafile 7 offline';
          ?
          ??? RMAN> Restore datafile 7;
          ??? RMAN> Recover datafile 7;
          ?
          ??? RMAN> SQL 'Alter tablespace datafile 7 online' ;
          ??? RMAN> Alter database open;
          ?
          ??? 附:文件號查詢SQL
          ??? select ts.tablespace_name, df.file_name, df.file_id, tf.file_name
          ??? from dba_tablespaces ts, dba_data_files df, dba_temp_files tf
          ??? where ts.tablespace_name = df.tablespace_name(+)
          ??? and ts.tablespace_name = tf.tablespace_name(+)
          ?
          ?
          五、恢復(fù)控制文件:
          ?
          ??? RMAN> Shutdown immediate;
          ??? RMAN> Startup nomount;
          ?
          ??? RMAN> Restore controlfile to 'xxxxxxxxxx'; --恢復(fù)控制文件
          ?
          ??? RMAN> Alter database mount;
          ?
          ??? RMAN> Restore database;
          ??? RMAN> Recover database;
          ?
          ??? RMAN> Alter database open;
          ?
          ?
          六、不完全恢復(fù):
          ?
          ??? 1、基于時(shí)間:
          ?
          ??? RMAN> Run {
          ????????? Allocate channel ch1 type disk;
          ????????? Set until time ' 06-OCT-08 10:00:00 ';
          ????????? Restore database;
          ????????? Recover database;
          ????????? SQL 'alter database open resetlogs';}
          ?
          ??? 2、基于日志序列號:
          ?
          ??? RMAN> Run {
          ????????? Allocate channel ch1 type disk;
          ????????? Set until logseq=2 thread=4;? --日志序號;文件線程號
          ????????? Restore database;
          ????????? Recover database;
          ????????? SQL 'alter database open resetlogs';}
          ?
          ??? 3、基于更改:
          ?
          ??? RMAN> Run {
          ????????? Allocate channel ch1 type disk;
          ????????? Set until scn n;? --事務(wù)號
          ????????? Restore database;
          ????????? Recover database;
          ????????? SQL 'alter database open resetlogs';}
          ?
          ?
          七、示例,直接copy來的
          ?

          C:\Documents and Settings\Administrator>sqlplus /nolog

          ?

          SQL*Plus: Release 9.2.0.1.0 - Production on 星期三 7 18 10:17:44 2007

          ?

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

          ?

          SQL> conn jss/jss

          已連接。

          SQL> create table tmp3(col varchar2(50));

          ###### 創(chuàng)建一個(gè)臨時(shí)表并插入一些數(shù)據(jù)

          表已創(chuàng)建。

          ?

          SQL> insert into tmp3 values ('test1');

          ?

          已創(chuàng)建 1 行。

          ?

          SQL> insert into tmp3 values ('test2');

          ?

          已創(chuàng)建 1 行。

          ?

          SQL> insert into tmp3 values ('test3');

          ?

          已創(chuàng)建 1 行。

          ?

          SQL> select *from tmp3;

          ?

          COL

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

          test1

          test2

          test3

          ?

          SQL> commit;

          ?

          提交完成。

          ?

          SQL> conn / as sysdba??? #### dba 用戶連接并關(guān)閉數(shù)據(jù)庫

          已連接。

          SQL> shutdown immediate;

          數(shù)據(jù)庫已經(jīng)關(guān)閉。

          已經(jīng)卸載數(shù)據(jù)庫。

          ORACLE 例程已經(jīng)關(guān)閉。

          ?

          SQL> host del F:\OraHome1\oradata\jssweb\jweb.ora

          ###### 手動刪除數(shù)據(jù)文件

          SQL> startup

          ORACLE 例程已經(jīng)啟動。

          ?

          Total System Global Area? 143727516 bytes

          Fixed Size?????????????????? 453532 bytes

          Variable Size???????????? 109051904 bytes

          Database Buffers?????????? 33554432 bytes

          Redo Buffers???????????????? 667648 bytes

          數(shù)據(jù)庫裝載完畢。

          ORA-01157: 無法標(biāo)識 / 鎖定數(shù)據(jù)文件 10 - 請參閱 DBWR 跟蹤文件

          ORA-01110: 數(shù)據(jù)文件 10: 'F:\ORAHOME1\ORADATA\JSSWEB\JWEB.ORA'

          ?

          ####### 看看,啟動報(bào)錯(cuò)了吧

          SQL> select instance_name,status from v$instance;

          ####### 看看當(dāng)前數(shù)據(jù)庫狀態(tài),應(yīng)該是處于 mount

          INSTANCE_NAME??? STATUS

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

          jssweb?????????? MOUNTED

          ?

          OK, 下面該 RMAN 出馬了。

          SQL>exit

          C:\Documents and Settings\Administrator>set oracle_sid=jssweb

          ?

          C:\Documents and Settings\Administrator>rman target /

          ?

          恢復(fù)管理器 : 版本 9.2.0 .1.0 - Production

          ?

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

          ?

          連接到目標(biāo)數(shù)據(jù)庫 : JSSWEB (DBID=3391142503)

          ?

          RMAN> restore datafile 'F:\ORAHOME1\ORADATA\JSSWEB\JWEB.ORA';

          #### 首先修復(fù)數(shù)據(jù)文件。 是不是有疑問,為什么不像上面第三節(jié)講的那樣先將該數(shù)據(jù)文件置為脫機(jī),笨啊你,數(shù)據(jù)庫都沒打開,脫什么機(jī)啊,整個(gè)數(shù)據(jù)庫現(xiàn)在都是脫機(jī)的。

          啟動 restore 18-7 -07

          ?

          正在使用目標(biāo)數(shù)據(jù)庫控制文件替代恢復(fù)目錄

          分配的通道 : ORA_DISK_1

          通道 ORA_DISK_1: sid=11 devtype=DISK

          通道 ORA_DISK_1: 正在開始恢復(fù)數(shù)據(jù)文件備份集

          通道 ORA_DISK_1: 正在指定從備份集恢復(fù)的數(shù)據(jù)文件

          正將數(shù)據(jù)文件 00010 恢復(fù)到 F:\ORAHOME1\ORADATA\JSSWEB\JWEB.ORA

          通道 ORA_DISK_1: 已恢復(fù)備份段 1

          handle=D:\BACKUP\1AIN4JU5_1_1 tag=TAG20070718T092837 params=NULL

          通道 ORA_DISK_1: 恢復(fù)完成

          完成 restore 18-7 -07

          ?

          RMAN> recover datafile 'F:\ORAHOME1\ORADATA\JSSWEB\JWEB.ORA';

          ######## 恢復(fù)數(shù)據(jù)文件

          啟動 recover 18-7 -07

          使用通道 ORA_DISK_1

          ?

          正在開始介質(zhì)的恢復(fù)

          完成介質(zhì)的恢復(fù)

          ?

          完成 recover 18-7 -07

          ?

          RMAN> alter database open;?? ######## 看起來很順利,打開數(shù)據(jù)庫看看

          ?

          數(shù)據(jù)庫已打開

          ?

          RMAN> host;

          ?

          Microsoft Windows [ 版本 5.2.3790]

          (C) 版權(quán)所有 1985-2003 Microsoft Corp.

          ?

          C:\Documents and Settings\Administrator>sqlplus jss/jss? #### 連到該用戶

          ?

          SQL*Plus: Release 9.2.0.1.0 - Production on 星期三 7 18 10:33:50 2007

          ?

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

          ?

          連接到 :

          Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

          With the Partitioning, OLAP and Oracle Data Mining options

          JServer Release 9.2.0.1.0 - Production

          ?

          SQL> select *from tmp3;???? ######查詢我們備份后創(chuàng)建的表

          ?

          COL

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

          test1

          test2

          test3

          #######yeah, 成功恢復(fù),沒有數(shù)據(jù)丟失。

          posted on 2008-09-15 21:33 decode360 閱讀(240) 評論(0)  編輯  收藏 所屬分類: 09.Recover

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 卓尼县| 寿阳县| 泾川县| 湖南省| 南部县| 肇源县| 阿尔山市| 纳雍县| 陕西省| 纳雍县| 明溪县| 南木林县| 杭州市| 景德镇市| 临沧市| 琼结县| 石河子市| 固安县| 聊城市| 滦南县| 大丰市| 新巴尔虎右旗| 浦城县| 始兴县| 岳阳市| 肇东市| 昌平区| 东乡族自治县| 昔阳县| 万宁市| 铁力市| 高陵县| 井冈山市| 读书| 通山县| 彭水| 大悟县| 聂拉木县| 游戏| 河东区| 垦利县|