오라클 온라인백업 스크립트 (ksh 용)

2010.05.12 08:48

조인상 조회 수:100773

원문 : http://www.ischo.net -- 조인상 // 시스템 엔지니어

Writer : http://www.ischo.net -- ischo // System Engineer in Replubic Of Korea

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

본문 : http://www.ischo.net -- 조인상 //시스템 엔지니어

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

#!/bin/ksh

############################################
# Programmed by Cho in-sang  (c)DSN    #
# chosim1@naver.com  http://www.ischo.net    #
#
# ORACLE ONLINE BACKUP SCRIPT          #
############################################

 


############################################
#  ENVIRONMENT SETTING              #
############################################

# 1. ORACLE SID #########################################
OSID=ORCL
export ORACLE_SID=${OSID}

# 2. BACKUP DESTINATION DIRECTORY #######################
DEST=/DBMS/PSFA/test
DEST_DF=${DEST}/datafile/${OSID}
DEST_CF=${DEST}/control/${OSID}
DEST_ARC=${DEST}/arch/${OSID}


# 3. ARCHIVE LOG BACKUP MODE ############################
# archived log backup enable
ARCenable=yes

# archived log retention
ARCretention=5

########################################################
################ END OF ENV SETTING ####################
########################################################

########################################################
# Make Directory if not exist
########################################################

if [ ! -d ${DEST_DF} ];
then
        mkdir -p ${DEST_DF}
fi

if [ ! -d ${DEST_CF} ];
then
        mkdir -p ${DEST_CF}
fi

if [ ! -d ${DEST_ARC} ];
then
        mkdir -p ${DEST_ARC}
fi

########################################################
########################################################

rm -rf $DEST/*lst*
rm -rf $DEST/*.sql
rm -rf $DEST/datafile.sh


############################################
#  TRIMMING BACKUP FILES            #
############################################


# export Archived-log PATH name
function Func_TrimArchLog
{
cd ${DEST}
sqlplus '/ as sysdba' << !

spool arc.lst
archive log list;
spool off

!

ARCPATH=`cat ${DEST}/arc.lst | grep "Archive destination" | grep -v grep | awk '{print $3}'`
}

 

# Function - export and trim tablespaces and datafiles
function Func_TrimTSandDF
{

cd ${DEST}
sqlplus '/ as sysdba' << !

spool begin_ts.lst
select distinct 'alter tablespace ' || tablespace_name || ' begin backup;' from dba_data_files;
spool off

spool end_ts.lst
select distinct 'alter tablespace ' || tablespace_name || ' end backup;' from dba_data_files;
spool off


spool datafile.lst
select 'FILENAME: ' || file_name from dba_data_files;
spool off


!

# TRIM TABLESPACE LIST
cat ${DEST}/begin_ts.lst | grep alter | grep -v SQL > ${DEST}/beginbackup.sql
cat ${DEST}/end_ts.lst | grep alter | grep -v SQL > ${DEST}/endbackup.sql


# TRIM DATAFILE LIST
cat ${DEST}/datafile.lst | grep "FILENAME:" | grep -v SQL | grep -v FILE_NAME | awk '{print $2}' > ${DEST}/datafile.lst2
for DATAFILES in `cat ${DEST}/datafile.lst2`
do


        TARGET_DIR=`echo ${DATAFILES%/*}`
        TARGET_FILE=`echo ${DATAFILES##/*/}`

        if [ ! -d ${DEST_DF}/${TARGET_DIR} ];
        then
                mkdir -p ${DEST_DF}/${TARGET_DIR}
        fi

        echo "cp -p ${DATAFILES} ${DEST_DF}/${TARGET_DIR}" >> ${DEST}/datafile.sh
done

}


# make controlfile backup shell
function Func_TrimControlFile
{
rm ${DEST_CF}/control01.ctl
rm ${DEST_CF}/control.trc
echo "alter database backup controlfile to '${DEST_CF}/control01.ctl';" > ${DEST}/control.sql
echo "alter database backup controlfile to trace as '${DEST_CF}/control.trc';" >> ${DEST}/control.sql
}


# DATAFILE,CONTROLFILE BACKUP
function Func_BackupStart
{
cd ${DEST}

sqlplus '/ as sysdba' << !

alter system switch logfile;

@beginbackup.sql

!/bin/ksh datafile.sh

@endbackup.sql

@control.sql

alter system switch logfile;

!
}

# Archived log backup & delete
function Func_BackupArc
{
if [ ${ARCenable} = yes ]
then
        find ${ARCPATH} -type f -mtime +${ARCretention} -exec rm {} \;
        cd ${ARCPATH}
        tar cf - . | (cd ${DEST_ARC};tar xf -)
        find ${DEST_ARC} -type f -mtime +${ARCretention} -exec rm {} \;
fi
}

###############################################################################
###############################################################################

 

###############################################################################
# Backup Start
###############################################################################

# 1. Trim Archived-log Path Name
Func_TrimArchLog

# 2. Trim TableSpace,DataFile Names and make backup script
Func_TrimTSandDF
Func_TrimControlFile

# 3. Start Oracle Online Backup(datafile,controlfile)
Func_BackupStart

# 4. Backup Archived-log files and delete old files.
Func_BackupArc

 

 

 

 

 

번호 제목 글쓴이 날짜 조회 수
115 exp error - ORA-19206: Invalid value for query or REF CURSOR parameter 조인상 2010.05.12 156631
114 centOS 5.2 에 오라클 10g 설치 조인상 2010.05.12 109931
» 오라클 온라인백업 스크립트 (ksh 용) [1] file 조인상 2010.05.12 100773
112 ORA-28040 : No matching authentication protocol 조인상 2014.11.13 67285
111 히든 파라미터 확인하는 쿼리 조인상 2010.05.12 62448
110 성능분석을 위한 v$sysstat, v$sesstat, v$system_event 조회 조인상 2011.09.27 50449
109 오라클 패치후 각 컴퍼넌트들 버전 확인 쿼리 조인상 2010.10.05 46331
108 exp실행시 에러. ORA-06512 SYS.DBMS_METADATA_INT 조인상 2010.05.12 32654
107 오라클 11g - ADR/ADRCI : 새로운 alertlog 위치 조인상 2011.05.17 29718
106 오라클에 접속하는 최대 인스턴스개수(세션개수)를 늘리는 방법 조인상 2010.05.12 24653
105 datafile, redolog, controlfile 위치 변경하기 조인상 2012.08.02 24615
104 일반유저에게 kill session 권한 주기 ischo 2019.08.12 22270
103 ORA-04063: package body "EXFSYS.DBMS_EXPFIL_EXP" has errors 조인상 2012.01.04 20761
102 온라인 백업방법 begin~end backup 조인상 2010.05.12 20669
101 windows용 오라클 온라인 백업 스크립트 file 조인상 2010.07.01 20143
100 SQL developer 실행시 jvm.dll 오류 발생 조치 방법 조인상 2013.01.23 19760
99 Oracle 설치문서에서 보는 ASM file 조인상 2012.03.30 19746
98 online backup(archive log mode) 조인상 2010.05.12 19439
97 ORA-01089 : 오라클 프로세스를 kill 한 후 로그인 못 할때 조인상 2010.06.20 19426
96 ORA-01555 : snapshot too old: rollback segment number %s with name \"%s\" too small ischo 2012.04.10 19263
서버에 요청 중입니다. 잠시만 기다려 주십시오...