본문 바로가기
DBMS/ORACLE

[oracle] RMAN 백업 스크립트

by 드바 2024. 7. 11.
로컬영역에 RMAN을 이용하여 백업 진행 시 스크립트
crontab에 등록하여 매일 full backup 진행

 

RMAN 백업 스크립트

14일 이전 백업파일 삭제

database full backup

archive log 백업

control file 백업

#!/bin/bash
. ~/.bash_profile

export BACKDIR="/home/ora19ent/back"

if [ ! -d $BACKDIR ]; then
   mkdir -p $BACKDIR
fi

rman target / <<+
RUN {
crosscheck backup;
DELETE NOPROMPT BACKUP COMPLETED BEFORE 'SYSDATE-14';   # 실제파일 지워짐 주의
BACKUP DATABASE FORMAT '$BACKDIR/full_%d_%s_%p_%T.rman' ;
crosscheck archivelog all;
BACKUP ARCHIVELOG ALL FORMAT '$BACKDIR/arch_%d_%s_%p_%T.rman' DELETE INPUT ;
BACKUP CURRENT CONTROLFILE FORMAT '$BACKDIR/ctrl_%d_%s_%p_%T.rman';
sql "alter database backup controlfile to trace as ''$BACKDIR/control01.sql'' reuse" ;
}
+

 

crontab 등록

매일 01시 백업 진행

rman 로그는 불필요하므로 /dev/null 2>&1 구문을 넣어줍니다

[ora19ent@svr ~]$ crontab -l
0 1 * * * /home/ora19ent/bck.sh >/dev/null 2>&1

 

수행로그

지난 백업 파일 삭제 진행 하는 것 확인 가능

[ora19ent@svr ~]$ sh bck.sh 

Recovery Manager: Release 19.0.0.0.0 - Production on Fri Jul 12 01:00:58 2024
Version 19.3.0.0.0

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

connected to target database: ENT19 (DBID=980639087)

RMAN> 2> 3> 4> 5> 6> 7> 8> 
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=265 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/ora19ent/back/full_ENT19_176_1_20240712.rman RECID=176 STAMP=1174092603
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/ora19ent/back/arch_ENT19_177_1_20240712.rman RECID=177 STAMP=1174092610
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/ora19ent/back/ctrl_ENT19_178_1_20240712.rman RECID=178 STAMP=1174092612
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/ora19ent/product/dbs/c-980639087-20240712-09 RECID=179 STAMP=1174092613
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/ora19ent/back/full_ENT19_180_1_20240712.rman RECID=180 STAMP=1174093204
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/ora19ent/back/arch_ENT19_181_1_20240712.rman RECID=181 STAMP=1174093211
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/ora19ent/back/ctrl_ENT19_182_1_20240712.rman RECID=182 STAMP=1174093213
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/ora19ent/product/dbs/c-980639087-20240712-0a RECID=183 STAMP=1174093214
Crosschecked 8 objects


using channel ORA_DISK_1

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
176     176     1   1   AVAILABLE   DISK        /home/ora19ent/back/full_ENT19_176_1_20240712.rman
177     177     1   1   AVAILABLE   DISK        /home/ora19ent/back/arch_ENT19_177_1_20240712.rman
178     178     1   1   AVAILABLE   DISK        /home/ora19ent/back/ctrl_ENT19_178_1_20240712.rman
179     179     1   1   AVAILABLE   DISK        /ora19ent/product/dbs/c-980639087-20240712-09
deleted backup piece
backup piece handle=/home/ora19ent/back/full_ENT19_176_1_20240712.rman RECID=176 STAMP=1174092603
deleted backup piece
backup piece handle=/home/ora19ent/back/arch_ENT19_177_1_20240712.rman RECID=177 STAMP=1174092610
deleted backup piece
backup piece handle=/home/ora19ent/back/ctrl_ENT19_178_1_20240712.rman RECID=178 STAMP=1174092612
deleted backup piece
backup piece handle=/ora19ent/product/dbs/c-980639087-20240712-09 RECID=179 STAMP=1174092613
Deleted 4 objects


Starting backup at 12-JUL-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/ora19ent/oradata/ENT19/system01.dbf
input datafile file number=00003 name=/ora19ent/oradata/ENT19/sysaux01.dbf
input datafile file number=00004 name=/ora19ent/oradata/ENT19/undotbs01.dbf
input datafile file number=00007 name=/ora19ent/oradata/ENT19/users01.dbf
channel ORA_DISK_1: starting piece 1 at 12-JUL-24
channel ORA_DISK_1: finished piece 1 at 12-JUL-24
piece handle=/home/ora19ent/back/full_ENT19_184_1_20240712.rman tag=TAG20240712T010100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 12-JUL-24

Starting backup at 12-JUL-24
current log archived
using channel ORA_DISK_1
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=57 RECID=49 STAMP=1174093267
channel ORA_DISK_1: starting piece 1 at 12-JUL-24
channel ORA_DISK_1: finished piece 1 at 12-JUL-24
piece handle=/home/ora19ent/back/arch_ENT19_185_1_20240712.rman tag=TAG20240712T010108 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/home/ora19ent/arch/1_57_1115563313.arc RECID=49 STAMP=1174093267
Finished backup at 12-JUL-24

Starting backup at 12-JUL-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 12-JUL-24
channel ORA_DISK_1: finished piece 1 at 12-JUL-24
piece handle=/home/ora19ent/back/ctrl_ENT19_186_1_20240712.rman tag=TAG20240712T010109 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUL-24

Starting Control File and SPFILE Autobackup at 12-JUL-24
piece handle=/ora19ent/product/dbs/c-980639087-20240712-0b comment=NONE
Finished Control File and SPFILE Autobackup at 12-JUL-24

sql statement: alter database backup controlfile to trace as ''/home/ora19ent/back/control01.sql'' reuse

RMAN> 

Recovery Manager complete.
[ora19ent@svr ~]$

댓글