Oracle/RMAN

RMAN으로 전체 데이터베이스 백업하면서 필요없는 파일 까지 지우기 ; delete noprompt obsolete이용

에몽이ㅋ 2012. 3. 30. 11:53
run {
backup database;
delete noprompt obsolete;
}

* 위 명령어로 인해 지워지는 파일 :
이전 backupset
현재까지 archive되었던 archivelog파일

* delete obsolete는 redundancy 설정에 영향을 받습니다.

포스팅의 목적 : 
archivelog mode로 운영도중에 FRA가 모자라서 경고가 뜨고, 곧 hang이 걸릴 것같은 상황이 오면 archivelog를 지워야 할 상황이 오는데,
이때 마구잡이로 파일을 삭제해버리면, 나중에 복구할때 문제가 발생할 수 있습니다.
archivelog file은 전체 데이터베이스 백업 이전의 것만 지울 수 있는데, 그때를 위한 포스팅입니다.

*주의사항
rman에서 delete noprompt obsolete; 만 실행하게 되면, 가장 최근의 backupset 까지 지워버리므로, 
항상 run {}안에 backup database;와 함께 써주셔야 합니다.


실습:
현재상황 확인
ASMCMD> cd fra/db1/archivelog
ASMCMD> ls
2012_03_30/
ASMCMD> cd 2012_03_30
ASMCMD> ls
thread_1_seq_16.260.779281685
thread_1_seq_17.257.779281693
thread_1_seq_18.262.779281697
thread_1_seq_19.263.779281697
thread_1_seq_20.264.779281703
thread_1_seq_21.265.779281703
thread_1_seq_22.266.779281707
 여러개의 아카이브로그가 존재합니다.

이후 rman에서 스크립트 실행
RMAN> run {
2> backup database;
3> delete noprompt obsolete;
4> }

Starting backup at 2012-03-30:11:10:48
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=50 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=41 devtype=DISK
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00003 name=+DATA/db1/datafile/sysaux.257.779279201
input datafile fno=00002 name=+DATA/db1/datafile/undo1.258.779279243
channel ORA_DISK_1: starting piece 1 at 2012-03-30:11:10:48
channel ORA_DISK_2: starting compressed full datafile backupset
channel ORA_DISK_2: specifying datafile(s) in backupset
input datafile fno=00001 name=+DATA/db1/datafile/system.256.779279199
channel ORA_DISK_2: starting piece 1 at 2012-03-30:11:10:48
channel ORA_DISK_1: finished piece 1 at 2012-03-30:11:11:04
piece handle=/home/oracle/rman/0nn75pdo_1_1_20120330.rman tag=TAG20120330T111048 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2012-03-30:11:11:04
channel ORA_DISK_2: finished piece 1 at 2012-03-30:11:11:04
piece handle=/home/oracle/rman/0on75pdo_1_1_20120330.rman tag=TAG20120330T111048 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:16
channel ORA_DISK_2: starting compressed full datafile backupset
channel ORA_DISK_2: specifying datafile(s) in backupset
channel ORA_DISK_1: finished piece 1 at 2012-03-30:11:11:05
piece handle=/home/oracle/rman/0pn75pe8_1_1_20120330.rman tag=TAG20120330T111048 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
including current SPFILE in backupset
channel ORA_DISK_2: starting piece 1 at 2012-03-30:11:11:05
channel ORA_DISK_2: finished piece 1 at 2012-03-30:11:11:06
piece handle=/home/oracle/rman/0qn75pe8_1_1_20120330.rman tag=TAG20120330T111048 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:02
Finished backup at 2012-03-30:11:11:06

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
using channel ORA_DISK_2
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           14     2012-03-30:11:06:42
  Backup Piece       14     2012-03-30:11:06:42 /home/oracle/rman/0jn75p5k_1_1_20120330.rman
Backup Set           13     2012-03-30:11:06:39
  Backup Piece       13     2012-03-30:11:06:39 /home/oracle/rman/0kn75p5k_1_1_20120330.rman
Backup Set           15     2012-03-30:11:06:44
  Backup Piece       15     2012-03-30:11:06:44 /home/oracle/rman/0ln75p63_1_1_20120330.rman
Archive Log          8      2012-03-30:11:08:06 +FRA/db1/archivelog/2012_03_30/thread_1_seq_16.260.779281685
Backup Set           16     2012-03-30:11:06:45
  Backup Piece       16     2012-03-30:11:06:45 /home/oracle/rman/0mn75p64_1_1_20120330.rman
Archive Log          9      2012-03-30:11:08:12 +FRA/db1/archivelog/2012_03_30/thread_1_seq_17.257.779281693
Archive Log          10     2012-03-30:11:08:16 +FRA/db1/archivelog/2012_03_30/thread_1_seq_18.262.779281697
Archive Log          11     2012-03-30:11:08:19 +FRA/db1/archivelog/2012_03_30/thread_1_seq_19.263.779281697
Archive Log          12     2012-03-30:11:08:22 +FRA/db1/archivelog/2012_03_30/thread_1_seq_20.264.779281703
Archive Log          13     2012-03-30:11:08:22 +FRA/db1/archivelog/2012_03_30/thread_1_seq_21.265.779281703
Archive Log          14     2012-03-30:11:08:27 +FRA/db1/archivelog/2012_03_30/thread_1_seq_22.266.779281707
deleted backup piece
backup piece handle=/home/oracle/rman/0jn75p5k_1_1_20120330.rman recid=14 stamp=779281588
deleted backup piece
backup piece handle=/home/oracle/rman/0kn75p5k_1_1_20120330.rman recid=13 stamp=779281588
deleted backup piece
backup piece handle=/home/oracle/rman/0ln75p63_1_1_20120330.rman recid=15 stamp=779281603
deleted archive log
archive log filename=+FRA/db1/archivelog/2012_03_30/thread_1_seq_16.260.779281685 recid=8 stamp=779281686
deleted backup piece
backup piece handle=/home/oracle/rman/0mn75p64_1_1_20120330.rman recid=16 stamp=779281605
deleted archive log
archive log filename=+FRA/db1/archivelog/2012_03_30/thread_1_seq_17.257.779281693 recid=9 stamp=779281692
deleted archive log
archive log filename=+FRA/db1/archivelog/2012_03_30/thread_1_seq_18.262.779281697 recid=10 stamp=779281696
deleted archive log
archive log filename=+FRA/db1/archivelog/2012_03_30/thread_1_seq_19.263.779281697 recid=11 stamp=779281699
deleted archive log
archive log filename=+FRA/db1/archivelog/2012_03_30/thread_1_seq_20.264.779281703 recid=12 stamp=779281702
deleted archive log
archive log filename=+FRA/db1/archivelog/2012_03_30/thread_1_seq_21.265.779281703 recid=13 stamp=779281702
deleted archive log
archive log filename=+FRA/db1/archivelog/2012_03_30/thread_1_seq_22.266.779281707 recid=14 stamp=779281707
Deleted 11 objects


백업 후 상황확인
RMAN> list backupset;


List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
17      Full    30.59M     DISK        00:00:10     2012-03-30:11:10:58
        BP Key: 17   Status: AVAILABLE  Compressed: YES  Tag: TAG20120330T111048
        Piece Name: /home/oracle/rman/0on75pdo_1_1_20120330.rman
  List of Datafiles in backup set 17
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 348712     2012-03-30:11:10:48 +DATA/db1/datafile/system.256.779279199

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
18      Full    39.21M     DISK        00:00:14     2012-03-30:11:11:02
        BP Key: 18   Status: AVAILABLE  Compressed: YES  Tag: TAG20120330T111048
        Piece Name: /home/oracle/rman/0nn75pdo_1_1_20120330.rman
  List of Datafiles in backup set 18
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  2       Full 348711     2012-03-30:11:10:48 +DATA/db1/datafile/undo1.258.779279243
  3       Full 348711     2012-03-30:11:10:48 +DATA/db1/datafile/sysaux.257.779279201

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
19      Full    1.03M      DISK        00:00:00     2012-03-30:11:11:04
        BP Key: 19   Status: AVAILABLE  Compressed: YES  Tag: TAG20120330T111048
        Piece Name: /home/oracle/rman/0pn75pe8_1_1_20120330.rman
  Control File Included: Ckp SCN: 348734       Ckp time: 2012-03-30:11:11:04

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
20      Full    80.00K     DISK        00:00:01     2012-03-30:11:11:05
        BP Key: 20   Status: AVAILABLE  Compressed: YES  Tag: TAG20120330T111048
        Piece Name: /home/oracle/rman/0qn75pe8_1_1_20120330.rman
  SPFILE Included: Modification time: 2012-03-30:11:00:20
살펴보시면, 최근 backupset 만 존재합니다.
[oracle@server15 ~]$ asmcmd
ASMCMD> cd fra
ASMCMD> ls
DB1/
ASMCMD> cd db1
ASMCMD> ls
CONTROLFILE/
ONLINELOG/
아예 archivelog폴더자체가 지워졌습니다. 이후 archive file이 생성이 되면 폴더와 파일이 자동으로 생성됩니다.