RMAN恢复
restore(恢复数据文件)
recover(写日志)
1. redo(roll forward)
2. undo(roll back)
RPO/RTO
数据文件:
不归档方式下丢失一个数据文件:
SQL> archive log list
备份前工作:
SQL> create table t1(x varchar2(50)) tablespace users;
SQL> insert into t1 values ('friday, before backup');
SQL> commit;
备份:
SQL>查询v$datafile, v$logfile, v$tempfile, v$controlfile
SQL> shutdown immediate
$ cd $ORACLE_BASE/oradata/
$ cp -r orcl orcl.bak
$ cd $ORACLE_BASE/fast_recovery_area/orcl
$ cp control02.ctl control02.ctl.bak
SQL> startup
备份后工作:
SQL> insert into t1 values ('monday, after backup');
SQL> commit;
故障:
SQL> alter system flush buffer_cache;
$ cd $ORACLE_BASE/oradata/orcl
$ >users01.dbf
SQL> select * from t1; 报错
$ vi /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
$ dbv file=/u01/app/oracle/oradata/orcl/users01.dbf
恢复:
SQL> shutdown abort
$ cd $ORACLE_BASE/oradata
$ rm -rf orcl
$ mv orcl.bak orcl
$ cd $ORACLE_BASE/fast_recovery_area/orcl
$ mv control02.ctl.bak control02.ctl
SQL> startup
SQL> select * from t1;
归档模式下丢失一个数据文件:
SQL> archive log list
备份前工作:
SQL> create table t1(x varchar2(50)) tablespace users;
SQL> insert into t1 values ('friday, before backup');
SQL> commit;
备份:
RMAN> backup tablespace users tag "tbs_users_weekend_backup";
备份后工作:
SQL> select group#, sequence#, status, archived from v$log;
SQL> insert into t1 values ('after backup, logseq 7, archived');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t1 values ('after backup, logseq 8, archived');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t1 values ('after backup, logseq 9, archived');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t1 values ('after backup, logseq 10, current');
SQL> commit;
SQL> insert into t1 values ('after backup, logseq 10, current, uncommitted');
SQL> select * from t1;
故障:
SQL> shutdown abort
$ rm $ORACLE_BASE/oradata/orcl/users01.dbf
SQL> startup 报错
SQL> select open_mode from v$database;
$ vi /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
恢复:
RMAN> list backup of tablespace users;
RMAN> list archivelog all;
SQL> alter database datafile 4 offline; system和undo tbs不能offline
SQL> alter database open;
RMAN> restore datafile 4;
RMAN> recover datafile 4;
SQL> alter database datafile 4 online;
SQL> select * from t1;
通过不完全恢复解决用户的误操作:
SQL> archive log list
备份前工作:
SQL> create table t1(x varchar2(50)) tablespace users;
SQL> insert into t1 values ('before backup');
SQL> commit;
备份:
RMAN> backup database tag 'weekend_DB_full_backup';
备份后:
SQL> insert into t1 values ('after backup, before delete');
SQL> commit;
误操作:
SQL> select sysdate from dual;
SQL> select dbms_flashback.get_system_change_number from dual;
SQL> delete t1;
SQL> commit;
SQL> create table after_delete (x int); 正确的操作
SQL> insert into after_delete values (1);
SQL> commit;
恢复:
RMAN> run {
startup force mount;
set until scn= 1806683;
restore database;
recover database;
alter database open resetlogs;
}
set until time=’2015-10-26 11:13:23’; 基于时间点恢复
SQL> select * from t1;
SQL> select * from after_delete; 丢失
SQL> select group#, sequence#, status, archived from v$log;
通过不完全恢复解决归档日志不连续:
SQL> archive log list
备份前:
SQL> create table t1(x varchar2(50)) tablespace users;
SQL> insert into t1 values ('before backup');
SQL> commit;
备份:
RMAN> backup database tag 'weekend_DB_full_backup';
备份后:
SQL> select GROUP#, SEQUENCE#, STATUS, archived from v$log;
SQL> insert into t1 values ('after backup, logseq 1, archived');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t1 values ('after backup, logseq 2, archived');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t1 values ('after backup, logseq 3, archived');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t1 values ('after backup, logseq 4, archived');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t1 values ('after backup, logseq 5, current');
SQL> commit;
SQL> alter system checkpoint;
故障:
SQL> shutdown abort
$ rm /u01/app/oracle/oradata/orcl/users01.dbf
$ rm /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2016_03_01/o1_mf_1_5_cfbcxo84_.arc
恢复:
SQL> startup
先尝试只恢复一个数据文件失败。
RMAN> run {
startup force mount;
set until sequence 5;
restore database;
recover database;
alter database open resetlogs;
}
SQL> select * from t1;