专注于数据库技术研究和实践,目前就职于互联网金融企业,提供Oracle数据库技术支持和维护。 联系电话:18616803656
分类: Oracle
2014-04-25 11:43:08
I.备份所有归档日志文件
RMAN> BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
II.使用RMAN方式清除
RMAN清除方式会自动清除磁盘上的归档日志文件,同时会释放控制文件中对应的归档日志的归档信息。
可以基于不同的条件来清除归档日志,如基于SCN,基于SEQUENCE,基于TIME等方式。
对于上述的三种方式又可以配合from, until, between .. and .. 等等子句来限定范围,方式灵活多变。
下面的命令用于校验归档日志的有效性,列出无效的归档日志,以及以何种方式清除归档日志,列出几种常用的:
crosscheck archivelog all; --->校验日志的可用性
list expired archivelog all; --->列出所有失效的归档日志
delete archivelog until sequence 16; --->删除log sequence为16及16之前的所有归档日志
delete archivelog all completed before 'sysdate-7'; --->删除系统时间7天以前的归档日志,不会删除闪回区有效的归档日志
delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的
delete archivelog from time 'sysdate-1'; --->注意这个命令,删除系统时间1天以内到现在的归档日志
delete noprompt archivelog all completed before 'sysdate'; --->该命令清除所有的归档日志
delete noprompt archivelog all; --->同上一命令
III. Restore archivelog选项
1.RAC环境下需要加上Thread Number,不加默认是Thread 1
RMAN> restore archivelog from sequence 112 thread 2;
2.恢复全部归档日志文件
RMAN> restore archivelog all;
3.恢复Sequence范围
RMAN> restore archivelog from sequence 90 until sequence 98;
RMAN> restore archivelog sequence between 20 and 35;
4.恢复从第5个归档日志起
RMAN> restore archivelog from sequence 5;
RMAN> restore archivelog low sequence 5;
5.恢复7天内的归档日志
RMAN> restore archivelog from time 'sysdate-7';
6.恢复到哪个日志文件为止
RMAN> restore archivelog until sequence 110;
RMAN> restore archivelog high sequence 108;
7.改变恢复到另外路径下 则可用下面语句
set archivelog destination to '/u01/backup';
RMAN> run
2> {allocate channel c1 type disk;
3> set archivelog destination to '/u01/backup';
4> restore archivelog all;
5> release channel c1;
6> }
8.根据时间查看需要的备份集:
RMAN> list backup of archivelog time between "to_date('2014-04-24 11:00:00','yyyy-mm-dd hh24:mi:ss')" and "to_date('2014-04-24 14:30','yyyy-mm-dd hh24:mi:ss')";
恢复指定时间段
RMAN> run {
set archivelog destination to '/u01/backup';
SQL 'ALTER SESSION SET NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"';
restore archivelog time between '2014-04-24 11:00:00' and '2014-04-24 15:00:00';
}