1、进入rman
[root@db1 ~]# su - oracle [oracle@db1 ~]$ /u01/app/oracle/product/10.2.0/db/bin/rman
一般都设置了环境变量,所以可以直接执行 rman 命令,如下:
[oracle@db1 ~]$ rman Recovery Manager: Release 11.2.0.1.0 - Production on Fri Sep 25 16:18:03 2020 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. RMAN>
2、connect target /
RMAN> connect target / connected to target database: ORA11G (DBID=4206582437)
RMAN>
3、crosscheck archivelog all;
crosscheck archivelog all:验证的是DB的归档日志即log_archive_dest参数指定位置的文件,当手工删除了归档日志以后,Rman备份会检测到日志缺失,从而无法进一步继续执行Rman备份,所以此时需要手工执行crosscheck过程,查看所有的归档日志文件是否都是正常的然后再来执行Rman备份。
4、delete expired archivelog all;
这时候我们再去OEM中就看不到这些日志文件了,如果你的从来没有做过这个动作的话,我们可以比较这个动作前的controlfile和动作后的controlfile的文件大小。
Oracle 正确删除归档并回收空间的方法
一个 Oracle 归档日志经常满,表现为 /archivelog 这个文件空间占用 100%。大家总是抱怨 Oracle 为何没有归档维护工具,很多人直接删除了事,其实错了,Oracle有归档维护工具,而且很智能,可以正确的删除归档和 FlashBack。
不过切记:Oracle归档日志对于Oracle的数据恢复和备份非常重要,不到万不得已不要删除归档日志。
删除归档日志的过程,如下:
1、以 oracle 用户身份登录
以 oracle 用户身份登录到数据库服务器主机或者通过网络连接。
2、进入Oracle数据备份工具
[oracle@db ~]# rman RMAN> rman target /
或者
/u01/app/oracle/product/10.2.0/db/bin/rman target/
或者
/u01/app/oracle/product/10.2.0/db/bin/rman target/@DTHXRAC1
3、在RMAN命令窗口里操作
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
说明:SYSDATE-7 ,表明当前的系统时间 7天前。before 关键字表示在7天前的归档日志,如果使用了闪回功能,也会删除闪回的数据。
同理,有可以删除从7天前到现在的全部日志,不过这个命令要考虑清楚,做完这个删除,最好马上进行数据库全备份。
RMAN> DELETE ARCHIVELOG FROM TIME 'SYSDATE-7';
Unix/Linux 下也可以通过 find 命令找到7天前的归档数据,使用 exec 子操作删除,如下:
find /archivelog -xdev -mtime +7 -name "*.dbf" -exec rm -f {} \;
这样做仍然会在 RMAN 里留下未管理的归档文件,它的作用还是相当于直接用操作系统命令将归档日志文件直接删除,而 Oracle 控制文件并不知道,因此仍需要在 RMAN 里执行下面两条命令:
RMAN> crosscheck archivelog all; RMAN> delete expired archivelog all;
所以,还不如上面的方法好用,不过用 find 命令的好处就是,可以在条件上和 exec 子项做很多操作,实现更复杂的功能。
简单介绍一下 report obsolete 命令
使用 report obsolete 命令报告过期备份:
RMAN> report obsolete; RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 1 Report of obsolete backups and copies Type Key Completion Time Filename/Handle -------------------- ------ ------------------ -------------------- Backup Set 125 01-NOV-04 Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804 Backup Set 131 04-NOV-04 Backup Piece 131 04-NOV-04 /data1/oracle/orabak/full_AVATAR2_20041104_131 .... Backup Set 173 06-DEC-04 Backup Piece 173 06-DEC-04 /data1/oracle/orabak/full_AVATAR2_20041206_173 Backup Set 179 11-DEC-04 Backup Piece 179 11-DEC-04 /data1/oracle/orabak/arch544588206.arc ..... Backup Piece 189 17-DEC-04 /data1/oracle/orabak/arch545106606.arc Backup Set 190 17-DEC-04 Backup Piece 190 17-DEC-04 /data1/oracle/orabak/arch545106665.arc Backup Set 191 20-DEC-04 Backup Piece 191 20-DEC-04 /data1/oracle/orabak/arch_AVATAR2_20041220_194 Archive Log 2973 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2985.dbf Archive Log 2971 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2984.dbf ..... Archive Log 2705 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2717.dbf Archive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbf Archive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbf Archive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbf
使用 delete obsolete 命令删除过期备份
RMAN> delete obsolete; RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 1 using channel ORA_DISK_1 Deleting the following obsolete backups and copies: Type Key Completion Time Filename/Handle -------------------- ------ ------------------ -------------------- Backup Set 125 01-NOV-04 Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804 .... Archive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbf Archive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbf Archive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbf Do you really want to delete the above objects (enter YES or NO)? yes deleted backup piece backup piece handle=/data1/oracle/orabak/full_AVATAR2_20041206_173 recid=173 stamp=544156241 ..... deleted archive log archive log filename=/opt/oracle/oradata/avatar2/archive/1_2715.dbf recid=2703 stamp=545108268 deleted archive log archive log filename=/opt/oracle/oradata/avatar2/archive/1_2714.dbf recid=2702 stamp=545107659 Deleted 286 objects RMAN> crosscheck archivelog all; allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=9 devtype=DISK validation succeeded for archived log archive log filename=/archivelog1/1_615_737652750.dbf recid=928 stamp=750848535 validation succeeded for archived log archive log filename=/archivelog1/1_616_737652750.dbf recid=930 stamp=750851615 Crosschecked 2 objects标签:04,archive,oracle,归档,Oracle,日志,DEC,Backup,RMAN From: https://www.cnblogs.com/ataoxz/p/18430500