当前位置: 首页 > BASIC > 正文

    下面测试来至于QQ群里与朋友聊天,使用脚本调用rm命令来删除归档日志,其实rman中的delete命令基本上可以满足我们需要,不需要使用rm命令来删除。下面是测试删除已经备份2次,5分钟之前生成的归档文件。

1 版本介绍

www.cdhtz.com > select * from v$version;

 

BANNER

——————————————————————————–

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production

PL/SQL Release 11.2.0.3.0 – Production

CORE    11.2.0.3.0      Production

TNS for Linux: Version 11.2.0.3.0 – Production

NLSRTL Version 11.2.0.3.0 – Production

 

www.cdhtz.com > !uname -a

Linux orcl9i 2.6.9-89.EL #1 Mon Apr 20 10:22:29 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

2  多次备份归档日志

这里使用switch logfile命令来切换日志,

www.cdhtz.com > set time on

06:24:49 www.cdhtz.com > alter system switch logfile;

System altered.

06:27:18 www.cdhtz.com > alter system switch logfile;

System altered.

备份归档日志

RMAN> backup archivelog all not backed up 2 times format ‘/soft/rman/ar_%s_%p_%t’;

 

Starting backup at 08-NOV-14

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=1 device type=DISK

skipping archived logs of thread 1 from sequence 1343 to 1344; already backed up

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=303 STAMP=863072653

input archived log thread=1 sequence=2 RECID=304 STAMP=863072685

input archived log thread=1 sequence=3 RECID=305 STAMP=863072694

input archived log thread=1 sequence=4 RECID=306 STAMP=863072848

input archived log thread=1 sequence=5 RECID=307 STAMP=863072869

channel ORA_DISK_1: starting piece 1 at 08-NOV-14

channel ORA_DISK_1: finished piece 1 at 08-NOV-14

piece handle=/soft/rman/ar_80_1_863072870 tag=TAG20141108T062750 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 08-NOV-14

切换日志

06:28:24 www.cdhtz.com > alter system switch logfile;

 

System altered.

 

再次备份归档日志

RMAN> backup archivelog all not backed up 2 times format ‘/soft/rman/ar_%s_%p_%t’;

 

Starting backup at 08-NOV-14

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=34 device type=DISK

skipping archived logs of thread 1 from sequence 1343 to 1344; already backed up

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=303 STAMP=863072653

input archived log thread=1 sequence=2 RECID=304 STAMP=863072685

input archived log thread=1 sequence=3 RECID=305 STAMP=863072694

input archived log thread=1 sequence=4 RECID=306 STAMP=863072848

input archived log thread=1 sequence=5 RECID=307 STAMP=863072869

input archived log thread=1 sequence=6 RECID=308 STAMP=863072911

input archived log thread=1 sequence=7 RECID=309 STAMP=863072953

channel ORA_DISK_1: starting piece 1 at 08-NOV-14

channel ORA_DISK_1: finished piece 1 at 08-NOV-14

piece handle=/soft/rman/ar_81_1_863072954 tag=TAG20141108T062914 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 08-NOV-14

又一次备份

RMAN> backup archivelog all not backed up 2 times format ‘/soft/rman/ar_%s_%p_%t’;

 

Starting backup at 08-NOV-14

current log archived

using channel ORA_DISK_1

skipping archived logs of thread 1 from sequence 1343 to 1344; already backed up

skipping archived logs of thread 1 from sequence 1 to 5; already backed up

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=6 RECID=308 STAMP=863072911

input archived log thread=1 sequence=7 RECID=309 STAMP=863072953

input archived log thread=1 sequence=8 RECID=310 STAMP=863072962

channel ORA_DISK_1: starting piece 1 at 08-NOV-14

channel ORA_DISK_1: finished piece 1 at 08-NOV-14

piece handle=/soft/rman/ar_82_1_863072962 tag=TAG20141108T062922 comment=NONE

channel ORA_DISK_1: backup set

 

06:29:58 www.cdhtz.com > alter system switch logfile;

 

System altered.

3 删除归档

删除5分钟前生成的,已经成功备份2次的归档文件,意味着要做删除sequence=8之前的所有的归档文件。

这里可以看到有如下的归档文件

[root@www.htz.pw nbu]#ls -lrt

total 41736

-rw-r—–  1 oracle oinstall 15620096 Nov  8 06:24 1_1_863072613.dbf

-rw-r—–  1 oracle oinstall 26667008 Nov  8 06:24 1_2_863072613.dbf

-rw-r—–  1 oracle oinstall   306176 Nov  8 06:24 1_3_863072613.dbf

-rw-r—–  1 oracle oinstall    40960 Nov  8 06:27 1_4_863072613.dbf

-rw-r—–  1 oracle oinstall     7168 Nov  8 06:27 1_5_863072613.dbf

-rw-r—–  1 oracle oinstall     1536 Nov  8 06:28 1_6_863072613.dbf

-rw-r—–  1 oracle oinstall     6656 Nov  8 06:29 1_7_863072613.dbf

-rw-r—–  1 oracle oinstall     1536 Nov  8 06:29 1_8_863072613.dbf

-rw-r—–  1 oracle oinstall    15872 Nov  8 06:30 1_9_863072613.dbf

 

06:39:02 www.cdhtz.com > select sysdate from dual;

 

SYSDATE

——————-

2014-11-08 06:39:08

 

06:39:08 www.cdhtz.com > !rman target /

 

Recovery Manager: Release 11.2.0.3.0 – Production on Sat Nov 8 06:39:11 2014

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORCL1123 (DBID=3499064767)

如果备份集存放在TAPE上面,需要将device type disk更改为device type tape;

RMAN> delete noprompt archivelog until time ‘sysdate-5/1440’ backed up 2 times to device type disk;

 

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=36 device type=DISK

RMAN-08138: WARNING: archived log not deleted – must create more backups

archived log file name=/oracle/nbu/1_8_863072613.dbf thread=1 sequence=8

RMAN-08138: WARNING: archived log not deleted – must create more backups

archived log file name=/oracle/nbu/1_9_863072613.dbf thread=1 sequence=9

List of Archived Log Copies for database with db_unique_name ORCL1123

=====================================================================

 

Key     Thrd Seq     S Low Time

——- —- ——- – ———

301     1    1343    A 07-NOV-14

        Name: /oracle/nbu/1_1343_849959296.dbf

 

302     1    1344    A 07-NOV-14

        Name: /oracle/nbu/1_1344_849959296.dbf

 

303     1    1       A 08-NOV-14

        Name: /oracle/nbu/1_1_863072613.dbf

 

304     1    2       A 08-NOV-14

        Name: /oracle/nbu/1_2_863072613.dbf

 

305     1    3       A 08-NOV-14

        Name: /oracle/nbu/1_3_863072613.dbf

 

306     1    4       A 08-NOV-14

        Name: /oracle/nbu/1_4_863072613.dbf

 

307     1    5       A 08-NOV-14

        Name: /oracle/nbu/1_5_863072613.dbf

 

308     1    6       A 08-NOV-14

        Name: /oracle/nbu/1_6_863072613.dbf

 

309     1    7       A 08-NOV-14

        Name: /oracle/nbu/1_7_863072613.dbf

 

deleted archived log

archived log file name=/oracle/nbu/1_1_863072613.dbf RECID=303 STAMP=863072653

deleted archived log

archived log file name=/oracle/nbu/1_2_863072613.dbf RECID=304 STAMP=863072685

deleted archived log

archived log file name=/oracle/nbu/1_3_863072613.dbf RECID=305 STAMP=863072694

deleted archived log

archived log file name=/oracle/nbu/1_4_863072613.dbf RECID=306 STAMP=863072848

deleted archived log

archived log file name=/oracle/nbu/1_5_863072613.dbf RECID=307 STAMP=863072869

deleted archived log

archived log file name=/oracle/nbu/1_6_863072613.dbf RECID=308 STAMP=863072911

deleted archived log

archived log file name=/oracle/nbu/1_7_863072613.dbf RECID=309 STAMP=863072953

Deleted 7 objects

 

[root@www.htz.pw nbu]#ls -lrt

total 20

-rw-r—–  1 oracle oinstall  1536 Nov  8 06:29 1_8_863072613.dbf

-rw-r—–  1 oracle oinstall 15872 Nov  8 06:30 1_9_863072613.dbf

这里可以看到只剩下89两个归档文件了。

在删除归档的时候,建议使用rmandelete命令,少使用操作系统的rm命令。

delete archivelog until time n backed up n times:等您坐沙发呢!

发表评论

gravatar

? razz sad evil ! smile oops grin eek shock ??? cool lol mad twisted roll wink idea arrow neutral cry mrgreen

快捷键:Ctrl+Enter