rman备份与恢复

备份

1级备份
[oracle@localhost autorman]$ vim level1.sh 
#!/bin/bash
source /home/oracle/.bash_profile
rman target / nocatalog log=/home/oracle/autorman/rman_1.log < run{
allocate channel d1 type disk format '/home/oracle/rman_level_1/1_%s_%p_%T.chen';
backup incremental level 1 database filesperset 3;
}
crosscheck backup;
crosscheck copy;
delete noprompt expired backup;
delete noprompt expired copy;
delete noprompt obsolete;
EOF



0级备份
[oracle@localhost autorman]$ vim level0.sh 
#!/bin/bash
source /home/oracle/.bash_profile
rman target / nocatalog log=/home/oracle/autorman/rman_0.log < run{
allocate channel d1 type disk format '/home/oracle/rman_level_0/0_%s_%p_%T.chen';
backup incremental level 0 database filesperset 3;
}
crosscheck backup;
crosscheck copy;
delete noprompt expired backup;
delete noprompt expired backup;
delete noprompt obsolete;
EOF


恢复


1: (1)数据文件恢复---关闭数据库的恢复


SQL> shutdown immediate


[oracle@chen orcl]$ rm -rf test01.dbf


SQL> startup
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'


SQL> select status from v$instance;


STATUS
------------
MOUNTED


[oracle@chen orcl]$ rman target / nocatalog


RMAN> run{
2> allocate channel d1 type disk;
3> restore datafile 6;
4> recover datafile 6;
5> }

SQL> alter database open;


(2)数据文件恢复---打开数据库的恢复

[oracle@chen orcl]$ vim test01.dbf
qqqq


SQL> select * from chen.b;
select * from chen.b
                   *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 138)
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'


SQL> alter database datafile 6 offline drop;  
归档模式下,offline 与 offline drop选项的作用相同。
非归档模式下,不允许直接 offline 数据文件,必须增加 drop 选项。


RMAN> run{
2> allocate channel d1 type disk;
3> restore datafile 6;
4> recover datafile 6;
5> sql 'alter database datafile 6 online';    
6> }

SQL> alter database open;


2:更改恢复目录

SQL> shutdown immediate

[oracle@chen orcl]$ rm -rf test01.dbf 

SQL> startup
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'

[oracle@chen orcl]$ rman target / nocatalog

RMAN> run{
2> allocate channel d1 type disk;
3> set newname for datafile 6 to '/home/oracle/rtest01.dbf';
4> restore datafile 6;
5> switch datafile 6;
6> recover datafile 6;
7> }

SQL> alter database open;


3:基于取消的不完全恢复


主要适用于:基于Cancel的不完全恢复适用场景:Recover时,所需的某个归档日志损坏,或主机断电,current状态的联机日志损坏。


删除orcl目录下所有文件


SQL> select name from v$controlfile;


NAME
-------------------------------------------------------
/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/flash_recovery_area/orcl/control02.ctl


[oracle@chen oradata]$ pwd
/u01/app/oracle/oradata


[oracle@chen oradata]$ rm -rf orcl/


SQL> shutdown immediate
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/orcl/control01.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


SQL> shutdown abort
ORACLE instance shut down.


[oracle@chen oradata]$ mkdir orcl


[oracle@chen flash_recovery_area]$ cp /u01/app/oracle/flash_recovery_area/orcl/control02.ctl /u01/app/oracle/oradata/orcl/


[oracle@chen orcl]$ mv control02.ctl control01.ctl 


SQL> startup mount


[oracle@chen oradata]$ rman target / nocatalog


RMAN> run{
2> allocate channel d1 type disk;
3> restore database;
4> recover database;
5> }

RMAN-03002: failure of recover command at 08/24/2014 01:57:46
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/home/oracle/archive_1/orcl_1856362828_15.arc'
ORA-00283: recovery session canceled due to errors
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/orcl/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

恢复失败原因:当前日志文件没有归档就被删除了

RMAN> run{
2> allocate channel t1 type disk;
3> set until time "to_date('2014-08-24 01:00:00','yyyy-mm-dd hh24:mi:ss')";
4> restore database;
5> recover database;
6> }
RMAN-03002: failure of recover command at 08/24/2014 02:03:25
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/home/oracle/archive_1/orcl_1856362828_15.arc'
ORA-00283: recovery session canceled due to errors
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/orcl/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
失败原因:时间不合理

RMAN> restore database;

SQL> recover database until cancel;
ORA-00279: change 1145507 generated at 08/24/2014 00:07:59 needed for thread 1
ORA-00289: suggestion : /home/oracle/archive_1/orcl_1856362828_16.arc
ORA-00280: change 1145507 for thread 1 is in sequence #16

Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.

SQL> alter database open resetlogs;

SQL> select * from chen.a;


    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

4:不完全恢复-基于时间恢复

[oracle@chen ~]$ date
Sun Aug 24 02:28:46 CST 2014

SQL> drop table chen.a purge;

SQL> select * from chen.a;
select * from chen.a
                   *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> shutdown immediate

SQL> startup mount

[oracle@chen ~]$ rman target / nocatalog

RMAN> run{
2> allocate channel d1 type disk;
3> set until time "to_date('2014-08-24 02:27:00','yyyy-mm-dd hh24:mi:ss')";
4> restore database;
5> recover database;
6> }

SQL> alter database open resetlogs;

SQL> select * from chen.a;


    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

http://www.ssc.stn.sh.cn/html/zjbk/2012-8/7555.html
--RESETLOGS会初始化logs,重置log sequence号,创建一个新的incarnation。
--NORESETLOGS 会继续使用已经存在,且有效的log files。
如果你恢复时使用了备份控制文件,那么打开数据库时必然是要resetlogs的。
不完全恢复,不管是要什么样的不完全恢复,SCN,TIME,跨越REDO,都必须使用resetlogs。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29785807/viewspace-1400271/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29785807/viewspace-1400271/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值