不徹底恢復:將數據庫恢復到過去的某個時間點或者SCN點
1、實驗環境
1.開歸檔
2.實驗操做
create table scott.lxtb3 tablespace lxtb as select * from scott.emp;
insert into scott.lxtb3 select * from scott.emp where rownum <=3;
select count(1) from scott.lxtb3;
3.利用LOGMNR挖掘日誌,找到對應操做的時間點和SCN
4.RMAN熱備全庫
2、備份恢復實驗
1.不徹底恢復至某DML語句前
DML-查日誌(v$log,v$logfile,v$archived_log)-logmnr找到操做的時間點和SCN-查數據文件-關庫-RMAN不徹底恢復至指定SCN;
7159512 2015-11-05 14:04:21
RMAN> startup mount;
run{
set until scn 7159512;
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
alter database open resetlogs;
}
2.不徹底恢復至某DDL語句
DDL-查日誌(v$log,v$logfile,v$archived_log)-logmnr找到操做的時間點和SCN-查數據文件-關庫-RMAN不徹底恢復至指定時間點;
7159731 2015-11-05 14:16:42
RMAN> startup mount;
run{
set until time '2015-11-05 14:16:42';
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
alter database open resetlogs;
}
3.基於cancel不徹底恢復(容易出問題,實驗前從新備份)
3DML-查當前日誌序列值,最近歸檔,數據文件-斷電-刪全部數據文件,最近一部分歸檔日誌,聯機日誌組因此成員-啓
查-設置sequence還原恢復數據庫-若是沒法恢復,下降sequence值再執行恢復(可用歸檔加1的sequence值)
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
}
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/11/2015 02:53:12
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of log thread 1 seq 13 lowscn 7196169 found to restore
RMAN-06025: no backup of log thread 1 seq 12 lowscn 7196139 found to restore
run{
set until sequence 13;
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
alter database open resetlogs;
}
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/11/2015 02:54:43
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of log thread 1 seq 12 lowscn 7196139 found to restore
--再設成12,會用12之前的日誌恢復,直到找到能夠恢復的狀態,恢復到12前的狀態
run{
set until sequence 12;
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
alter database open resetlogs;
}
--人工輔助恢復
SQL> recover database until cancel;
ORA-00279: change 3654542 generated at 07/31/2015 09:52:56 needed for thread 1
ORA-00289: suggestion : /u01/arc_dir/1_4_886492614.dbf
ORA-00280: change 3654542 for thread 1 is in sequence #4
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
若是:
Oracle Error:
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 2 was not restored from a sufficiently old backup
ORA-01110: data file 2: '/u01/app/oracle/oradata/ipemsdb/datafile/o1_mf_undotbs1_bvodsj2v_.dbf'
--下降sequence後再人工輔助
SQL> recover database until cancel;
Media recovery cancelled.
SQL> alter database open resetlogs;sql
4.基於舊的控制文件恢復
備份-備份控制文件-3DML-刪表空間和數據文件-查看錶空間,數據文件信息,日誌信息,歸檔信息-
logmnr分析drop時間-斷電-rman-啓nomount-還原控制文件-啓mount-rman不徹底恢復-若是還不行recover until timme
using backup controlfile-auto-再恢復-給聯機日誌-open resetlogs
有未提交的操做表空間不能刪除,刪除表空間時系統會自動備份控制文件,全部注意控制文件的選擇,表空間給恢復回來了
但是表沒了。。。
RMAN> startup nomount
RMAN> restore controlfile from '/u01/app/backdir/rman/controlfile/c-2694191837-20150731-1f'; --轉備份的
RMAN> alter database mount;
RMAN> report schema; --確認有須要的表空間
7201268 2015-11-11 04:11:40
run{
set until time '2015-11-11 04:11:40';
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
alter database open resetlogs;
}
run{
set until time '2015-11-11 04:11:40';
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
}數據庫
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/31/2015 11:45:52
RMAN-06054: media recovery requesting unknown log: thread 1 seq 1 lowscn 3658130服務器
recover database until time '2015-07-31 12:57:50' using backup controlfile;
auto
再次執行給日誌
alter database open resetlogs;oracle
3、catalog庫建立維護
恢復目錄自己有一組視圖,用於存放目標數據庫與備份信息,能夠保留更多的備份信息與方便的管理多個目標數據庫
做用:記錄rman生成備份的備份相關信息目標庫控制文件信息,10G90,11G142保存多個表;
備份信息集中管理;
執行腳本
建立:另一臺服務器,查表空間,數據文件信息,
建表空間,用戶,密碼文件,啓動監聽
建立表空間rc_data,一個庫20M,參照庫的多找設定表空間大小,
create tablespace rc_data datafile '/u01/app/oracle/oradata/ipemsdb/datafile/rc_data01.dbf' size 30M ;
建立user rc_damin
create user rc_admin identified by rc_admin default tablespace rc_data;
grant connect,resource to rc_admin;
賦權限角色recovery_catalog_owner
grant RECOVERY_CATALOG_OWNER to rc_admin;
alter user sys identified by oracle;
[oracle@redhat4_200 dbs]$ orapwd
[oracle@redhat4_200 dbs]$ orapwd file=orapwipemsdb password=oracle entries=3 force=y
[oracle@redhat4_200 dbs]$ sqlplus sys/oracle as sysdba
登錄測試:
啓監聽 啓動另外服務監聽
聯本機oracle 連動態的 互聯
先聯本機,再聯對方機器
[oracle@redhat4 ~]$ sqlplus sys/oracle@ipemsdb as sysdba
[oracle@redhat4 ~]$ sqlplus sys/oracle@jg200 as sysdba
[oracle@redhat4_200 dbs]$ sqlplus sys/oracle@ipemsdb2 as sysdba
[oracle@redhat4_200 dbs]$ sqlplus sys/oracle@jg100 as sysdbaapp
[oracle@redhat4 ~]$ rman target sys/oracle@ipemsdb
[oracle@redhat4 ~]$ rman catalog rc_admin/rc_admin@jg200
RMAN> create catalog;
[oracle@redhat4 ~]$ rman target sys/oracle@ipemsdb catalog rc_admin/rc_admin@jg200
RMAN> register database;
SQL> conn rc_admin/rc_admin
Connected.
SQL> select * from tab;
SQL> select * from rc_database;
SQL> select file#,name from rc_datafile;ide
rman target sys/oracle@
rmna catalog rc_admin/rc_admin@
rc_admin 登錄,查表
建立:
create catalog;
select * from rc_database;
rman target sys/oracle@ catalog rc_damin/rc_admin@
註冊:
register database;
相關表及執行腳本:
rc_database;
rc_datfile;
rc_stored_script;
rc_stored_script_line;
print cript
run{execute script name}
恢復目錄支持以下的命令
{CREATE|UPGRADE|DROP} CATALOG
{CREATE|DELETE|REPLACE|PRINT}
LIST INCARNATION
REGISTER DATABASE
REPORT SCHEMA AT TIME
RESET DATABASE
RESYNC CATALOG
RESYNC CATALOG命令
Resync能夠同步數據庫與恢復目錄之間的信息,在實際狀況下,rman通常能夠自動同步。在以下狀況下
須要同步數據庫物理結構的改變;數據文件增長或者是改變大小;表空間刪除;回滾段的建立與刪除;每產生10個歸檔日誌
RESET DATABASE命令
目標數據庫resetlogs以後,須要從新設置恢復目錄。Reset命令就用來從新設置恢復目錄。
指定備份文件所在目錄,此命令用於掃描整個目錄的備份片或者歸檔日誌文件等
catalog start with '/u02/database/SY5221_RMAN/20121013'; 測試