本篇总结一下RMAN命令中的DELETE操作,DELETE命令用于删除RMAN备份记录以及相应的物理文件。
To delete physical backups and copies as well as do the following:
1: Update their repository records in the target control file to status DELETED
2: Remove their repository records from the recovery catalog (if you use a catalog)
When running RMAN interactively, DELETE displays a list of the files and prompts
you for confirmation before deleting any file in the list. When reading commands from
a command file, RMAN will not prompt for confirmation.
DELETE removes the physical files from the backup media, deletes the record of
the backup from the recovery catalog (if RMAN is connected to a recovery catalog),
and updates the records of these backups in the control file to status DELETED
删除归档日志
删除某个Sequence之前(包含该Sequence)的归档日志
RMAN>delete archivelog until sequence xxx;
RMAN>delete archivelog from sequence xxx until sequence xxx;
删除系统时间1天以前的归档日志,不会删除闪回区有效的归档日志(可以指定删除多久日志)
RMAN>delete archivelog all completed before 'sysdate-1';
force参数表示会删除有效归档日志
RMAN>delete force archivelog all completed before 'sysdate-1';
删除某个时间段的归档日志,例如删除20天前到2天前的归档日志。
RMAN>delete archivelog from time 'sysdate-20' until time 'sysdate-2';
RMAN>delete archivelog from time 'sysdate-1';
注意:此命令会删除闪回区的有效归档日志。
删除所有的归档日志。
RMAN>delete noprompt archivelog all;
RMAN>delete noprompt archivelog all completed before 'sysdate';
RMAN> delete expired archivelog all;
注意:delete expired archivelog all 实际上此命令不会真正删除归档日志,它删除的是那些本来RMAN以为存在但是实际上在磁盘或者磁带上已经被删除了文件的信息,实际删除的只是RMAN资料库或控制文件中的记录;
RMAN> delete obsolete;
RMAN> delete noprompt obsolete;
注意:delete obsolete这个是清理过期备份,它也会删除过期的归档日志。但是特殊情况下,除闪回区有效的归档日志不会删除。
上面都是使用RMAN命令删除归档日志,最后一种方式,也是最不推荐的一种方式就是使用命令从系统系统删除归档日志,使用rm删除了备份文件后,需要执行crosscheck archivelog all命令校检归档日志是否失效。
删除备份
删除过期备份
删除过期备份,RMAN会根据备份冗余策略确定备份是否过期。然后删除过期的备份。
RMAN> report 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 1 18-MAY-17
Backup Piece 1 18-MAY-17 /u03/backup/backupsets/ora_df944345823_s1_s1
Control File Copy 1 18-MAY-17 /u03/backup/backupsets/controlfile.copy
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/u03/backup/backupsets/ora_df944345823_s1_s1 recid=1 stamp=944345824
deleted control file copy
control file copy filename=/u03/backup/backupsets/controlfile.copy recid=1 stamp=944347366
Deleted 2 objects