crontab에 등록해서 매일 백업 자동실행하기 2 7 15,019

by 다솜여우 [기타] crontab backup [2009.03.18 11:31:21]


crontab 등록.JPG (9,505Bytes)
crontab list.JPG (10,860Bytes)

cron으로 자동 백업하려는데, cron에 대해서 일반적인 내용은 많은데

설정한 결과와 어떻게 했는지에 대해서는 잘 안나와 있더라구요.

어렵지 않은데 저처럼 초보관리자는 참 대략 난감... ㅡ.ㅡ;;

시스템마다 설정이 다르겠지만 제가 맡고 있는 시스템에서 설정한 걸 올립니다.

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

●OS : Linux RedHat 5

● 빨간색은 주의할 부분이예요. 제가 설정하면서 놓쳤거나 자료에도 잘 안나와 있는 부분입니다.

 

1. 백업 스크립트 준비

    1) 스크립트에서는 반드시 ".bash_profile"에 있는 환경설정 내용이 들어가야 함

    2) SQL*PLUS로 실행할 쿼리는 "system"유저로 해야함 : 일반 유저로 실행하면 크론 실행 시 에러 발생

 

 

2. crontab 설정 : oracle유저로 cron실행시켜야 함

    1) root로 로그인

    2) cron.deny와 cron.allow 파일 존재 확인 : ls /etc

    3) cron.deny는 있으나 cron.allow 파일은 없음. 그래서 cron.allow 파일 생성

         vi cron.allow

             oracle

         esc + : + wq

    4) cron.deny 파일에 등록된 유저 확인 : 여기에 등록된 유저는 없었음

         more cron.deny

    5) oracle유저로 로그인

    6) 스크립트가 있는 파일 권한 설정 : export 백업은 oracle의 system이 실행하지만, 이 백업을 자동화할 수 있게 하는 것은 "cron"이므로 cron이 실행시킬 파일에 접근 해서 실행 할 수 있게 "755"로 권한을 설정한다.(관련 파일은 모두 755로 설정했음)

       ⓐ  chmod 755 /oracle/backup/exp/script/daily.sh

       ⓑ  chmod 755 /oracle/backup/exp/files

       ⓒ Note : cron으로 자동 실행할 파일은 파일은 모두 cron이 접근해서 실행가능하게 해야 하기에 파일이 새로 생성되면 반드시 권한을 설정한다. 

   

    7) cron 설정  : path에는 실행할 파일이 있는 경로도 적어준다.

        ⓐ 크론 수정 및 등록 : crontab -e

        ⓐ 크론 설정 확인  : crontab -l    

 

         ⓑ cron 등록 확인 : root유저로 확인

         ⓒ cron restart : cron을 등록하거나 수정하면은 재시작을 해줘야지 반영이 되었다.(재시작을 하지 않으면 cron은 실행되지 않음)

              su - root

              /etc/init.d/crond restart

 

3. 자동백업 결과 : mail로 자동실행 과정 결과가 발송됨

 The original message was received at Wed, 18 Mar 2009 10:21:01 +0900
from oracle@localhost

   ----- The following addresses had permanent fatal errors -----
root
    (reason: 553 5.5.4 <oracle@localhost.localdomain>... Real domain name required for sender address)
    (expanded from: root)

   ----- Transcript of session follows -----
... while talking to [127.0.0.1]:
>>> MAIL From:<oracle@localhost.localdomain> SIZE=6361
<<< 553 5.5.4 <oracle@localhost.localdomain>... Real domain name required for sender address
501 5.6.0 Data format error

--n2I1L1sa011660.1237340355/localhost.localdomain
Content-Type: message/delivery-status

Reporting-MTA: dns; localhost.localdomain
Arrival-Date: Wed, 18 Mar 2009 10:21:01 +0900

Final-Recipient: RFC822; root@localhost.localdomain
Action: failed
Status: 5.5.4
Diagnostic-Code: SMTP; 553 5.5.4 <oracle@localhost.localdomain>... Real domain name required for sender address
Last-Attempt-Date: Wed, 18 Mar 2009 10:39:15 +0900

--n2I1L1sa011660.1237340355/localhost.localdomain
Content-Type: message/rfc822

Return-Path: <oracle>
Received: (from oracle@localhost)
        by localhost.localdomain (8.13.8/8.13.8/Submit) id n2I1L1sZ011660;
        Wed, 18 Mar 2009 10:21:01 +0900
Date: Wed, 18 Mar 2009 10:21:01 +0900
Message-Id: <200903180121.n2I1L1sZ011660@localhost.localdomain>
From: root (Cron Daemon)
To: root
Subject: Cron <oracle@mcdb> /oracle/backup/exp/script/daily.sh
Content-Type: text/plain; charset=ISO-8859-1
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/bash>
X-Cron-Env: <PATH=/sbin:/bin:/usr/sbin:/usr/bin:/oracle/backup/exp/script>
X-Cron-Env: <MAILTO=root>
X-Cron-Env: <HOME=/>
X-Cron-Env: <LOGNAME=oracle>
X-Cron-Env: <USER=oracle>

Wed Mar 18 10:21:01 KST 2009
*************daily export Start *******************

SQL*Plus: Release 10.2.0.3.0 - Production on Wed Mar 18 10:21:01 2009

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SP2-0734: unknown command beginning "**********..." - rest of line ignored.
SP2-0734: unknown command beginning "02_USER_EX..." - rest of line ignored.
SP2-0734: unknown command beginning "**********..." - rest of line ignored.
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Wed Mar 18 10:21:02 KST 2009

Export: Release 10.2.0.3.0 - Production on Wed Mar 18 10:21:02 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Export done in KO16KSC5601 character set and AL16UTF16 NCHAR character set
server uses KO16MSWIN949 character set (possible charset conversion)

About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user NEWNC01
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user NEWNC01
About to export NEWNC01’s objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export NEWNC01’s tables via Conventional Path ...

..................
..................
..................

. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
Wed Mar 18 10:39:15 KST 2009
************* daily export End *******************
Wed Mar 18 10:39:15 KST 2009

--n2I1L1sa011660.1237340355/localhost.localdomain--

by 아라시 [2009.03.18 14:12:32]
저희 시스템에 적용했는데 잘 돌아가요...
이제 실시간 이기종 DB 스케줄러 테스트만 하면 되요...
^^* 누나는 정리 진짜 잘하시네요..

by 타락천사 [2009.03.18 14:24:09]
메일은 어떻게 발송되는건가요 ?
MAILT0=root 이 구분에서 ?
아니면 daily.sh 내부에있나요 ?

by 다솜여우 [2009.03.18 14:41:55]
확인은 아직 안 해봤지만 cron 환경 설정이 crontab에 등록하면 자동으로 "oracle"유저에게 실행결과가 메일로 보내지도록 되어 있는 것 같더라구요.
그리고 제가 일단은 "MAILT0=root "로 설정해서 root계정으로도 메일을 받게했어요.
즉, oracle & root 계정으로 cron실행 결과가 메일로 발송됩니다.
그런데, root계정의 메일이 너무 커서 MAILT0=""로 변경해야 할 것 같아요.
그리고 daily.sh 는 확인을 좀 해봐야 할 것 같아요...
확인하고 다시 리플 달께요~~^^;;

by 다솜여우 [2009.03.18 16:53:41]
흠...
모르겠어요...
어떻게 메일이 발송되는지....
리눅스를 공부해야할 것 같아요~~~ ㅡ.ㅡ;;
글고 나중에 이기종 DB 스케줄러 테스트 결과 좀 알려줘요.
궁금타...

by 아라시 [2009.03.18 17:08:05]
네 ^^*
데이터 포맷이랑 EXPORT/IMPORT 옵션만 잘 설정하면 되요
담 달 정도에 할 것 같으니까 하고 보고하겠습니다 ^^

by 다솜여우 [2009.03.18 17:44:12]
제가 잘못 쓴게 있습니다.
MAILT0=" "
이렇게 설정하면 oracle이나 root 계정으로도 메일이 가지 않습니다.

by 꽃순정 [2017.02.21 18:29:23]

정말 필요한 정보입니다. 정말정말 감사해요 ㅠㅠ 이것땜에 고객사에서 엄청 고생했어요 흑흑 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입