[Oracle - Export  ]

 


 Win오라클 export 자동 백업

 
 제목: 자동 export 및 정기적인 자동 삭제 배치파일 만들기
 
작성자: 강명호
작성일: 2004년 11월 26일
 
배치파일 장점
exp_daily.bat 배치파일을 수행할 경우 매일 export가 수행되고 
exp_delete.bat 배치파일을 수행할 경우 2, 3일의 백업을 항상 보유하며 주기적으로 삭제하기 때문에 더 이상 Disk가 꽉 차는 현상(Disk Full)을 막을 수 있다.
단점.
DB의 Size가 클 경우 매일 export 받는다면 Local Disk의 공간 부족 현상이 발생할 수 있다. 이런 경우에는 여러 개의 백업을 보유하기 힘들기 때문에 좀 더 주기적으로 삭제하거나 백업받은 파일을 압축하여 관리해야 한다. 백업하고 자동으로 압축하는 방법은 다음에... ^_^;;
 
 
1. 배치파일 만들기
시작 --> 실행 --> notepad  실행하여 각각 배치파일의 내용을 붙여넣기 한 다음 설정된 파일 이름으로 변경한다
 
exp_daily.bat
@echo off
SET ORACLE_SID=ORCL
for %%a in (%date%) do SET day=%%a
md D:\ORA_BACKUP\EXP\1\%day%
C:\oracle\ora92\BIN\EXP system/manager file=D:\ORA_BACKUP\EXP\1\%DAY%\%DAY%-full.dmp full=y  log=D:\ORA_BACKUP\EXP\1\%DAY%\%DAY%-full-exp.log
 
exp_daily.bat 설명
D:\ORA_BACKUP\EXP\1\ 하위 디렉토리에 날짜 폴더가 생성되고 
system 유저로 Full export를 수행하며 날짜 이름의 dmp, log 파일이 생성된다
 
exp_delete.bat
rd /s /q D:\ORA_BACKUP\EXP\2
move D:\ORA_BACKUP\EXP\1 D:\ORA_BACKUP\EXP\2
 
exp_delete.bat 설명
D:\ORA_BACKUP\EXP\2 디렉토리를 지우고 
D:\ORA_BACKUP\EXP\1 디렉토리를 D:\ORA_BACKUP\EXP\2 디렉토리로 폴더 이름을 변경한다.
 
 
2. 작업 예약 설정하기

매일 새벽 1시에 export 받는 작업 예약하기
C:\> at 01:00 /every:Su,M,T,W,Th,F,S D:\ORA_BACKUP\exp_daily.bat
 
매주 일,수 밤 10시에 백업 삭제하는 작업 예약하기
C:\> at 22:00 /every:Su,W D:\ORA_BACKUP\exp_delete.bat
 
AT 명령 변수 설명
 /every: date ,... : 
이 매개 변수를 사용하여 매주 금요일이나 매월 8일처럼 
지정된 요일이나 날짜에 작업을 실행하도록 예약합니다. 
하나 이상의 요일(다음 약자 사용: M,T,W,Th,F,S,Su)이나 
하나 이상의 날짜(숫자 1 - 31 사용)로 date를 지정합니다. 
쉼표를 사용하여 여러 날짜 항목을 구분해야 합니다. 
이 매개 변수를 생략하면 현재 날짜에 작업이 실행되도록 예약됩니다.
 
*** 주의 ***
SID, EXP 파일의 경로, 백업 받을 경로, export주기, 삭제 설정은 사용자의 환경에 맞게 수정하여 사용하면 된다.

 Windows 2000 서버에서 오라클 백업하기

 
제가 사용하는 스크립트 입니다.
설명을 붙이 자면 날짜와 시간을 받아서 화일명을  바꾸는 배치화일을 만들고
At 이라는 스케줄러를 이용하여 백업을 합니다.
 
물론 Exp 를 이용하여 벡업을 하고 있습니다.
 
참고로  Doff 라는 프로그램을 이용하며 날짜을 넘겨 받을수 있도록 합니다.(하단 소스 참고)
 
============================================================================
# at 04:00 /every:M,T,W,Th,F,S,Su E:ORACLE_BKscriptfullbackup.bat
at 03:00 /every:M,T,W,Th,F,S,Su E:ORACLE_BKscriptuserdump.bat
at 04:00 /every:M,W,F,Su E:ORACLE_BKscriptfullbackup.bat
=============================================================================
 
================================ Full backup.bat===============================
@echo off
 
for /f "tokens=1-3 delims=/ " %%a in ('doff mm/dd/yyyy -1') do (
set mm=%%a
set dd=%%b
set yyyy=%%c)
 
e:
cd E:ORACLE_BK

rename fullbackup.dmp fullbackup-%yyyy%%mm%%dd%.dmp
exp system/systempass file='E:ORACLE_BKfullbackup.dmp' full=y
===================================================================
 
 
================================ userdump.bat===============================
@echo off
for /f "tokens=1-3 delims=/ " %%a in ('doff mm/dd/yyyy -1') do (
set mm=%%a
set dd=%%b
set yyyy=%%c)
 
e:
cd E:ORACLE_BK

rename user.dmp user-%yyyy%%mm%%dd%.dmp
exp userid=user/userpass file='E:ORACLE_BKuser.dmp'
===================================================================
 
=============================doff.exe ========================================
* 
** doff - prints a formatted date string offset by a specified time interval
**
** File:    doff.c
** Author:  John Fitzgibbon (fitz@jfitz.com http://www.jfitz.com)
** Version: 1.0
** Date:    11/08/1999
**
** This program and code is FREEWARE.
**
**  Command line format: doff [format_str [offset_str [exclude_format_str]]]
**  doff -h to display help.
**
**  Revision History
**  11/08/1999 1.0 Original Version 
*/
char helpstr[] = 
"doff - Prints a formatted date string offset by a specified time intervaln"
"syntax is: doff [format_str [offset_str [exclude_format_str]]]n"
"       or: doff -h   (displays this help screen)n"
"n"
"format_str, (case sensitive), may include any of the following:n"
"  yyyy - replaced by four digit year in output stringn"
"  yy - replaced by two digit year in output stringn"
"  mm - replaced by month (1 - 12) in output stringn"
"  dd - replaced by day (1 - 31) in output stringn"
"  hh - replaced by hour (0 - 23) in output stringn"
"  mi - replaced by minute (0 - 59) in output stringn"
"  ss - replaced by second (0 - 59) in output string (leap seconds = 59)n"
"Other characters in format_str are returned as-isn"
"n"
"offset_str, (case sensitive), is specified as [+/-]n[smhd]n"
"  "n" is the offset valuen"
"  offset qualifiers are: s = seconds, m = minutes, h = hours, d = daysn"
"n"
"exclude_format_str has the same format as format str.n"
"Patterns in exclude_format_str that would normally be translated are ignored.n"
"For example, including "ss" in exclude_format_str means "ss" will appearn"
"untranslated in the output string.n"
"n"
"Default offset value is zero, default offset qualifier is daysn"
"Bad offset values default to zero, bad offset qualifiers default to daysn"
"Note: -10xd will evaluate to "10 days ago", (because atoi("-10x") = -10)n"
"  but -x10d will evaluate to "now", (because atoi("-x10") = 0)n"
"n"
"When both format_str and offset_str are omitted the output format is:n"
"yyyymmddhhmissn";
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
int main (int argc, char * argv[])
{
  time_t etime;
  struct tm * stime;
  char dstr[15];
  char * cp;

  if ((argc > 1) && !strncmp(argv[1],"-h",2))
  {
    puts(helpstr);
    exit(0);
  }
  time(&etime);
  if (argc > 2)
  {
    if ((cp = strstr(argv[2],"s")) != NULL) // offset seconds
    {
      *cp = '

스크랩을 하면서...
doff를 이용하여 날짜를 파일 이름에 넣을 수 있습니다.
 

'(DB) Oracle > Object & Utility' 카테고리의 다른 글

Oracle - Data를 Insert 문장으로 만들기  (0) 2017.01.21
Oracle - Export Script  (0) 2017.01.21
Oracle - SQL*PLUS  (0) 2017.01.21
Oracle - Sequence  (0) 2017.01.21
Oracle - Gateway 사용 하기  (0) 2017.01.21
Posted by 농부지기
,