rman資料庫恢複;關鍵/非關鍵檔案、影像副本、控制檔案、還原點、非歸檔、增量、新資料庫、災難性回複,rman副本

來源:互聯網
上載者:User

rman資料庫恢複;關鍵/非關鍵檔案、影像副本、控制檔案、還原點、非歸檔、增量、新資料庫、災難性回複,rman副本

執行完全恢複:在 ARCHIVELOG 模式下 丟失了系統關鍵資料檔案:

如果某個資料檔案丟失或損壞,且該檔案屬於 SYSTEM 或 UNDO 資料表空間,請執行以下步驟:

1.
執行個體可能會也可能不會自動關閉。
2.如果未自動關閉,請使用 SHUTDOWN ABORT 關閉執行個體。
3.
裝載資料庫。
4.
還原並恢複缺失的資料檔案。

5.開啟資料庫。

 

1.歸檔模式丟失非關鍵資料檔案  完全恢複

第一種方法:

shutdown abort;

startup mount;

alter database create datafile '/home/oracle/test.dbf' as '/home/oracle/test.dbf';

recover datafile;

第二種方法:

create tablespace test datafile '/home/oracle/test.dbf' size 10m;

rman target /

backup datafile 5;

rm test.dbf

sq> alter database datafile 5 offline;

restore datafile 5;

recover datafile 5;

sq> alter database datafile 5 online;

select FILE#,STATUS from v$datafile;

 

2. 歸檔模式丟失關鍵資料檔案  完全恢複

利用備份,同上第二種方法。

 

--------------------------------------------------------------------------------------------------------------
復原映像副本:
RMAN> recover copy of database with tag 'daily_inc';

RMAN> backup incremental level 1 for recover of copy
with tag 'daily_inc' database;

                          RECOVER                   BACKUP
第 1 天              無                                  建立映像副本
第 2 天              無                                  建立 1 級增量備份
第 3 天和以後  根據增量備份恢複副本   建立 1 級增量備份


復原映像副本:樣本
如果每天都運行以上命令,則可以隨時獲得所有資料庫資料檔案的連續更新的映像副本。
圖表顯示了每次運行所發生的操作。請注意,這種演算法需要一段準備期間;到第 3 天后策略才會起作用。

第 1 天
RECOVER 命令沒有執行任何操作。尚不存在要恢複的映像副本。BACKUP 命令可用於建立映像副本。

第 2 天
RECOVER 命令仍沒有執行任何操作。因為尚不存在增量備份。由於已在第 1 天建立了基準映像副本,BACKUP 命令會建立增量備份。
第 3 天
RECOVER 命令將增量備份中的更改應用於映像副本。BACKUP 命令將執行另一個增量備份,該備份將在第 4 天用於復原映像副本,依此進行迴圈。

 

執行到映像副本的快速切換
執行以下步驟

可以使用資料檔案的映像副本進行快速恢複:

1.使資料檔案離線。
2.使用 SWITCH TO ...COPY 命令指向這些檔案的映像副本。

3.恢複資料檔案。
4.使資料檔案聯機。


此時,資料庫是可用的,且資料檔案已恢複。但是,如果您希望將資料檔案放回其原始位置,請繼續執行以下步驟:


5.使用 BACKUP AS COPY 命令在原始位置建立資料檔案的映像副本。

6.使資料檔案離線。

7.使用 SWITCH TO COPY 命令切換到在步驟 5 中建立的副本。

8.恢複資料檔案。

9.使資料檔案聯機。
可以使用此命令來恢複資料檔案、資料表空間、臨時檔案或整個資料庫。切換到的目標檔案必須為映像副本。

3. 映像副本的快速切換

backup as copy datafile 6;

rm a.dbf

sql:alter database datafile 6 offline;

rman >switch datafile '/home/oracle/test.dbf' to copy;

recover datafile 6;

--回複後資料檔案的路徑和名稱為 '/home/oracle/test.dbf';

 

alter database datafile 4 online;

select FILE#,STATUS from v$datafile;

select file_name from dba_data_files;

 

backup as copy datafile 4 format '/u01/app/oracle/oradata/orcln/users01.dbf';

alter database datafile 4 offline;

switch datafile ' /home/oracle/backup/db_data_D-ORCL_I-4115975543_TS-TEST_FNO-6_38otbf5q.bak' to copy;

switch datafile 4 to copy;

recover datafile 4;

alter database datafile 4 online;

select file_name from dba_data_files;

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

 

4. set newname 改名字

backup as copy datafile 6;

list copy of datafile 6;

select FILE#,STATUS from v$datafile;

 

 

run{

   allocate channel c1 device type disk;

   sql "alter database datafile 6 offline";

   set newname for datafile '/home/oracle/test.dbf' to '/home/oracle/test_new.dbf';

   restore datafile 6;

   switch datafile all;

   recover datafile 6;

   sql "alter database datafile 6 online";

   }


--------------------------------------------------------------------------------------------------------------
從自動備份還原控制檔案:

RMAN> STARTUP NOMOUNT;

RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;

RMAN> ALTER DATABASE MOUNT;

RMAN> RECOVER DATABASE;

RMAN> ALTER DATABASE OPEN RESETLOGS;

 

7. 丟失控制檔案,參數檔案 --資料庫必須在nomount狀態

查看檔案資訊:

SQL>select name from v$controlfile;

SQL>show parameter spfile;

SQL> select name from v$datafile;

 

配置控制檔案自動備份恢複控制檔案

rman target /

connected to target database: ORCL (DBID=1353286769)

RMAN>show all; 

RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON;

 

資料庫全備份:

RMAN>backup as compressed backupset full database;

 

刪除,參數檔案,控制檔案,資料檔案

rm /opt/oracle/oradata/orcl/control01.ctl

rm /opt/oracle/flash_recovery_area/orcl/control02.ctl

rm /opt/oracle/oradata/orcl/control03.ctl

rm /opt/oracle/product/11.2.2/dbs/spfileorcl.ora

rm /opt/oracle/oradata/orcl/system01.dbf

rm /opt/oracle/oradata/orcl/sysaux01.dbf

rm /opt/oracle/oradata/orcl/undotbs01.dbf

rm /opt/oracle/oradata/orcl/users01.dbf

rm /home/oracle/tbs_ctl01.dbf

 

rman target /

RMAN> set dbid 1353286769  --如果備份在

startup nomount  --雖然沒有參數檔案但是也可以啟動執行個體

 

恢複參數檔案:

restore spfile from '/data/backup/ctl_c-1353286769-20131102-04.bak';

 

/* 從快速恢複區恢複參數檔案:

run { 

restore spfile from autobackup 

recovery area = 'flash recovery area destination' 

db_name = 'db_name'; 

*/

 

查看是否有需要改的參數:主要看檔案位置

SQL> create pfile from spfile; 

 

恢複控制檔案:

restore controlfile to '/opt/oracle/oradata/orcl/control01.ctl' from '/data/backup/ctl_c-1353286769-20131102-04.bak';

 

恢複資料檔案:

RMAN> shutdown immediate

RMAN> startup mount

RMAN> restore database;

RMAN> recover database;

RMAN> alter database open;

 

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of alter db command at 11/02/2013 12:10:46

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

 

RMAN> alter database open resetlogs;


--------------------------------------------------------------------------------------------------------------
使用增量備份恢複處於 NOARCHIVELOG 模式的資料庫:

STARTUP FORCE NOMOUNT;

RESTORE CONTROLFILE; 

ALTER DATABASE MOUNT;

RESTORE DATABASE;

RECOVER DATABASE NOREDO;

ALTER DATABASE OPEN RESETLOGS;

8. 使用增量備份恢複處於NOARCHIVELOG 模式的資料庫

   1) 撤銷資料庫archivelog模式

   SQL>shutdown immediate;

   SQL>startup mount;

   SQL>alter database noarchivelog;

   SQL>alter database open;

   SQL>archive log list;

 

   2) 建立測試用表及資料

   conn zhuxy/zhuxy

   create table c (id number);

   insert into c values(1);

   commit;

 

   3) 在noarchivelog模式下,0級備份

   RMAN> run{

    shutdown immediate;

    startup mount;

    backup as backupset incremental level 0 database;

    alter database open;

    }

 

   4) 在noarchivelog模式下,1級備份

   insert into c values(2);

   commit;

 

   RMAN> run{

    shutdown immediate;

    startup mount;

    backup as backupset incremental level 1 database;

    alter database open;

   }

 

   6) 刪除所有記錄檔,  某些資料檔案 

 

   7) 執行恢複

   rman target /

   RMAN>startup mount;

 

   --執行全庫的還原

   RMAN> restore database;

 

   -- 使用noredo子句進行恢複

   RMAN> recover database noredo;

 

   --恢複完成,resetlogs方式開啟資料庫,完成所有檔案丟失的恢複

   RMAN> alter database open resetlogs;

 

   8)驗證在測試前(增量備份前)插入的資料

    select * from c;

 

6.非歸檔丟失檔案

不完全恢複: SCN, 時間,還原點,或記錄序號     

1確定目標還原點:SCN、時間、還原點或記錄序號。 

2設定 NLS 環境變數。 

3裝載資料庫。 

4使用 SET UNTIL、RESTORE 和 RECOVER 命令準備並運行 RUN 塊。 

5用 RESETLOGS 開啟資料庫。

 

-----不完全恢複之--基於時間的恢複 

   1) 準備環境:RMAN全庫備份

   RMAN> backup as compressed backupset full database;

   2) 準備環境:測試表及資料

   alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

   create table d (c date);

   insert into d values(sysdate);

   commit;

   create table ff (c date);

   insert into ff values(sysdate);

   commit;

 

   啟動到mount模式,進行基於時間的恢複

   shutdown immediate;

   startup mount;

 

run

{sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';

set until time = ' 2014-03-30 00:39:34';

restore database;

recover database;

alter database open resetlogs;

}

時間也可以這麼寫:

set until time="to_date('2013-11-01 15:29:34','yyyy-mm-dd hh24:mi:ss')";

-----還原點:

select count(*)  from copy_emp; 

建立還原點:

create restore point before_delete;

delete from copy_emp where ID >=10;

commit;

alter table copy_emp enable row movement;

flashback table copy_emp to restore point b;

--------------------------------------------------------------------------------------------------------------
將資料庫還原到新主機:

為了還原資料庫,請在還原主機上執行以下步驟:

1.配置 ORACLE_SID 環境變數。

2.啟動 RMAN 並在 NOCATALOG 模式下串連到目標執行個體。

3.設定資料庫標識符 (DBID)。

4.在 NOMOUNT 模式下啟動執行個體。
5.
從備份組中還原伺服器參數檔案。

6.關閉執行個體。
7.
編輯還原的初始化參數檔案。
8.
在 NOMOUNT 模式下啟動執行個體
9.建立 RUN 塊以執行下列任務:

  --還原控制檔案
  --
裝載資料庫

10.建立 RMAN 恢複指令碼以還原和恢複資料庫。

11.執行 RMAN 指令碼。

12.使用 RESETLOGS 選項開啟資料庫。

9 利用備份將資料庫還原到新主機:目標庫需要有oracle軟體

 

1)準備工作

   源庫資料庫全備及控制檔案自動備份,當然也包括參數檔案

   RMAN> backup as backupset database;

 

2)拷貝RMAN備份檔案到目標庫

  可以用scp

 

3)配置目標庫

  目標庫設定環境變數

  export ORACLE_SID=new_orcl

 

 啟動rman到nomount狀態,設定dbid(即源庫dbid)

 $ rman target /

 RMAN> set dbid 1357901988

 RMAN> startup nomount; --沒有參數檔案,會報錯,但是可以啟動執行個體

 

4)恢複參數檔案

 

RMAN> restore spfile to pfile '' from '';

 

編輯pfile參數檔案:檔案位置,資料庫執行個體名..,建立相應的目錄

 

5) 啟動資料庫到nomount模式 

 SQL> create spfile from pfile;

 SQL> startup nomount;

 

6)還原控制檔案

 

$ rman target /

 

RMAN> restore controlfile to '' from '';

 

RMAN> alter database mount;

 

7) 還原資料檔案

   run{

SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata/orcl/system01.dbf';

SET NEWNAME FOR DATAFILE 2 TO '/u01/app/oracle/oradata/orcl/sysaux01.dbf';

SET NEWNAME FOR DATAFILE 3 TO '/u01/app/oracle/oradata/orcl/undotbs01.dbf';

SET NEWNAME FOR DATAFILE 4 TO '/u01/app/oracle/oradata/orcl/users01.dbf';

SET NEWNAME FOR DATAFILE 5 TO '/u01/app/oracle/oradata/orcl/example01.dbf';

SET NEWNAME FOR DATAFILE 6 TO '/u01/app/oracle/oradata/orcl/test.dbf';

RESTORE DATABASE;

SWITCH DATAFILE ALL;

RECOVER DATABASE;}

 

--rename記錄檔

run{

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ENMOEDU/redo01.log'' TO 

''/u01/app/oracle/oradata/orcl/redo01.log'' ";

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ENMOEDU/redo02.log'' TO 

''/u01/app/oracle/oradata/orcl/redo02.log'' ";

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ENMOEDU/redo03.log'' TO 

''/u01/app/oracle/oradata/orcl/redo03.log'' ";

}

 

RMAN> alter database open resetlogs;

 

8)臨時檔案位置不對

SQL> select file_name from dba_temp_files;

SQL>create temporary tablespace tempa tempfile 

'/u01/app/oracle/oradata/orcl/tempa01.dbf' size 10m reuse autoextend on  maxsize  200m;

SQL>alter database default temporary tablespace tempa;

SQL>drop tablespace temp;

SQL>select file_name from dba_temp_files;

 

注:這個測試改變了執行個體名

 

 


--------------------------------------------------------------------------------------------------------------
執行災難恢複 :

災難意味著丟失了整個目標資料庫、恢複目錄資料庫、所有當前控制檔案、所有聯機重做記錄檔和所有參數檔案。


災難恢複包括還原和恢複目標資料庫。


備份組的最低要求: 

1.資料檔案的備份
2.
相應的歸檔重做記錄檔
3.
至少一個控制檔案自動備份

基本過程:
1.
還原伺服器參數檔案的自動備份。

2.啟動目標資料庫執行個體。

3.從自動備份還原控制檔案。

4.裝載資料庫。

5.還原資料檔案。

6.恢複資料檔案。

7.使用 RESETLOGS 選項開啟資料庫。

 

 

 


 


oracle:直接物理刪除了資料檔案,資料庫啟動不起來

1 從資源回收筒中將刪除的資料檔案複原 即可啟動
2 如果資源回收筒中也被刪除了。
那麼sysdba進入
alter database datafile 'D:\ORADATA\TEST\TEST\users03.dbf' offline 非歸檔

alter database datafile 'D:\ORADATA\TEST\TEST\users03.dbf' offline drop; 歸檔
 
我用rman對資料庫做了增量備份,結果伺服器攤了,我重新裝了oracle,但我有考出備份檔案,不知怎恢複

你的備份檔案時什嗎?我再回答你的問題
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.