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

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



(스크립트) 오라클 DB서버에서  매일 원격지 FTP로 export 파일 업로드 하기



목표  : 오라클DB서버 (리눅스) 에서 매일 export backup 후 원격지 FTP서버로 파일 업로드



아래 스크립트 작성후 실행권한을 주고 crontab 에 등록하여 사용.




#!/bin/bash

#####################################
### ENV #############################
#####################################
# DATE
DATE=`date '+%Y%m%d'`

# LOCAL BACKUP DIRECTORY NAME
LOCAL_DIR=/backup/daily


# ORACLE ENVIRONMENT
ORA_USER="system"
ORA_PASS="manager"

# FTP SERVER ENVIRONMENT
FTP_SERVER="ftpremoteserver_address"
FTP_USER="ftpusername"
FTP_PASS='ftpuserpassword'
FTP_DEST="/remoteserverdirectory_in_absolute_path"


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


### backup
function func_backup
{

exp ${ORA_USER}/${ORA_PASS} file=${LOCAL_DIR}/${ORA_USER}_${DATE}_full.dmp log=${LOCAL_DIR}/${ORA_USER}_${DATE}_full.log full=y

gzip ${LOCAL_DIR}/${ORA_USER}_${DATE}_full.dmp
gzip ${LOCAL_DIR}/${ORA_USER}_${DATE}_full.log

# delete 30 days old backup files
find ${LOCAL_DIR} -name "*full*.gz" -type f -mtime +30 -exec rm {} \;

}


### FTP backup

function func_ftp
{
ftp -n ${FTP_SERVER} << !
user ${FTP_USER} ${FTP_PASS}
cd ${FTP_DEST}
lcd ${LOCAL_DIR}
bin
prompt
mput ${ORA_USER}_${DATE}_full.dmp.gz
mput ${ORA_USER}_${DATE}_full.log.gz

bye
!
}


#####################################
### MAIN PROCEDURE
#####################################

func_backup

sleep 1

func_ftp


############# END OF SCRIPT ################



(*.118.235.233)