행위

"데이터 Export 와 Import"의 두 판 사이의 차이

DB CAFE

(DB전체 입력)
(DB_LINK를 이용한 IMPORT)
 
(같은 사용자의 중간 판 21개는 보이지 않습니다)
30번째 줄: 30번째 줄:
 
== DB전체 백업 ==
 
== DB전체 백업 ==
 
* conventional Path 로 받기
 
* conventional Path 로 받기
<source lang=sql>
+
<source lang=sql >
 
exp system/oracle full=y log=full_log.log file=/home/oracle/full_test001.dmp
 
exp system/oracle full=y log=full_log.log file=/home/oracle/full_test001.dmp
 
</source>
 
</source>
  
 
* Direct Path 로 받기
 
* Direct Path 로 받기
<source lang=sql>
+
<source lang=sql highlight=5>
exp system/oracle full=y log=full_log.log file=/home/oracle/full_test001.dmp '''direct=y'''
+
exp system/oracle  
 +
full=y  
 +
log=full_log.log  
 +
file=/home/oracle/full_test001.dmp  
 +
direct=y
 
</source>
 
</source>
  
 
== 파일 분할 백업 ==
 
== 파일 분할 백업 ==
<source lang=sql>
+
<source lang=sql highlight=[3,4,5,6,7]>
 
exp system/oracle full=y  
 
exp system/oracle full=y  
'''file=(/backup/test_001.dmp,\
+
 
 +
file=(
 +
/backup/test_001.dmp,\
 
/backup/test_002.dmp,\
 
/backup/test_002.dmp,\
 
/backup/test_003.dmp,\
 
/backup/test_003.dmp,\
 
/backup/test_004.dmp)\'''
 
/backup/test_004.dmp)\'''
 +
 
filesize=100M  
 
filesize=100M  
 
log=full_log.log direct=y
 
log=full_log.log direct=y
51번째 줄: 58번째 줄:
  
 
== 해당 테이블 스페이스만 백업 ==
 
== 해당 테이블 스페이스만 백업 ==
<source lang=sql>
+
<source lang=sql highlight=6>
exp system/oracle full=y log=full_log.log file=/home/oracle/full_test001.dmp '''tablespaces=(example,undotbsl)'''
+
exp system/oracle  
 +
full=y  
 +
log=full_log.log  
 +
file=/home/oracle/full_test001.dmp  
 +
 
 +
tablespaces=(example,undotbsl)
 +
 
 
</source>
 
</source>
  
 
== 여러 사용자 백업 ==
 
== 여러 사용자 백업 ==
<source lang=sql>
+
<source lang=sql highlight=3>
exp system/oracle file=/home/oracle/full_test001.dmp '''owner=(scott,tiger)'''
+
exp system/oracle  
 +
file=/home/oracle/full_test001.dmp  
 +
owner=(scott,tiger)
 +
 
 
</source>
 
</source>
  
64번째 줄: 80번째 줄:
 
* Direct Path
 
* Direct Path
 
<source lang=sql>
 
<source lang=sql>
exp system/oracle full=y log=full_log.log file=/home/oracle/full_test001.dmp buffer=20140000 direct=y '''tables=(example,undotbsl)'''
+
exp system/oracle  
 +
full=y  
 +
log=full_log.log  
 +
file=/home/oracle/full_test001.dmp  
 +
buffer=20140000  
 +
direct=y  
 +
tables=(example,undotbsl)
 
</source>
 
</source>
  
70번째 줄: 92번째 줄:
 
## 권한확인
 
## 권한확인
 
<source lang=sql>
 
<source lang=sql>
  SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'SCOTT';
+
  SELECT *  
 +
  FROM DBA_ROLE_PRIVS  
 +
WHERE GRANTEE = 'SCOTT';
 
</source>
 
</source>
  
 
## 권한부여
 
## 권한부여
 
<source lang=sql>
 
<source lang=sql>
  GRANT EXP_FULL_DATABASE TO SCOTT;
+
  GRANT EXP_FULL_DATABASE  
 +
    TO SCOTT;
 
</source>
 
</source>
 
* DBA권한을 부여 해도 됨(권장하지 않음)
 
* DBA권한을 부여 해도 됨(권장하지 않음)
  
 
== 파라메터를 이용하여 백업 ==
 
== 파라메터를 이용하여 백업 ==
<source lang=sql>
+
<source lang=sql highlight=2>
exp system/oracle '''parfile=para_file.txt'''
+
exp system/oracle  
 +
parfile=para_file.txt
 
</source>
 
</source>
 
- para_file.txt  
 
- para_file.txt  
93번째 줄: 119번째 줄:
 
*parfile 옵션을 사용하여 파라메터로 사용하면 편리  
 
*parfile 옵션을 사용하여 파라메터로 사용하면 편리  
 
<source lang=sql>
 
<source lang=sql>
exp scott/tiger '''query=\"where ename like \'F%\'\"''' tables=emp file =/data/emp.dmp
+
exp scott/tiger  
 +
query=\"where ename like \'F%\'\"
 +
tables=emp file =/data/emp.dmp
 
</source>
 
</source>
  
169번째 줄: 197번째 줄:
 
</source>
 
</source>
  
== 일부 사용자만 입력 ====
+
== 일부 사용자만 입력 ==
 
<source lang=sql>
 
<source lang=sql>
imp system/oracle file=/home/oracle/full_test001.dmp '''fromuser=(scott,tiger)''' tables=test01 ignore=y
+
imp system/oracle  
 +
file=/home/oracle/full_test001.dmp  
 +
fromuser=(scott,tiger)  
 +
tables=test01 ignore=y
 
</source>
 
</source>
  
== 테이블 소유자를 변경하여 입력  ====
+
== 테이블 소유자를 변경하여 입력  ==
 
<source lang=sql>
 
<source lang=sql>
imp system/oracle file=/home/oracle/full_test001.dmp '''fromuser=scott''' touser=tiger ignore=y
+
imp system/oracle  
 +
file=/home/oracle/full_test001.dmp  
 +
fromuser=scott
 +
touser=tiger  
 +
ignore=y
 
</source>
 
</source>
  
== DDL만 추출하기 ====
+
== DDL만 추출하기 ==
 
* show=y 옵션사용 방법 - 로그에 저장하여 ddl 편집  
 
* show=y 옵션사용 방법 - 로그에 저장하여 ddl 편집  
 
* indexfile 옵션을 사용하는 방법
 
* indexfile 옵션을 사용하는 방법
 
<source lang=sql>
 
<source lang=sql>
imp system/oracle file=/data/test02.dmp full=y show=y log=scott_ddl.sql
+
imp system/oracle  
 +
file=/data/test02.dmp  
 +
full=y  
 +
show=y  
 +
log=scott_ddl.sql
 
</source>
 
</source>
  
== import 시 테이블과 index 분리 ====
+
== import 시 테이블과 index 분리 ==
* import시 indexes=n 옵션으로 import후 인덱스 별도 생성
 
  
== 인덱스 파일만 별도 추출 ====
+
* import시 indexes=n 옵션으로 import후 인덱스 별도 생성
<source lang=sql>
+
 
imp system/oracle file=/data/test02.dmp indexfile=scott_index.sql full=y
+
== 인덱스 파일만 별도 추출 ==
 +
<source lang=sql highlight=2>
 +
imp system/oracle  
 +
file=/data/test02.dmp indexfile=scott_index.sql  
 +
full=y
 
</source>
 
</source>
  
== [[데이터펌프 IMPORT API#|DB_LINK를 이용한 IMPORT]] ==
+
== DB_LINK를 이용한 IMPORT ==
 +
{{:데이터펌프 IMPORT API}}
  
  
 
[[Category:oracle]]
 
[[Category:oracle]]

2021년 6월 3일 (목) 14:27 기준 최신판

thumb_up 추천메뉴 바로가기


1 EXPORT[편집]

1.1 EXPORT 옵션[편집]

build 데이터 EXPORT 옵션
* userid
* buffer
* file
* grants
* indexes
* rows
* constraints
* compress
* full
* owner
* tables
* tablespaces
* recordlength
* inctype
* record
* parfile

1.2 DB전체 백업[편집]

  • conventional Path 로 받기
exp system/oracle full=y log=full_log.log file=/home/oracle/full_test001.dmp
  • Direct Path 로 받기
exp system/oracle 
full=y 
log=full_log.log 
file=/home/oracle/full_test001.dmp 
direct=y

1.3 파일 분할 백업[편집]

exp system/oracle full=y 

file=(
/backup/test_001.dmp,\
/backup/test_002.dmp,\
/backup/test_003.dmp,\
/backup/test_004.dmp)\'''

filesize=100M 
log=full_log.log direct=y

1.4 해당 테이블 스페이스만 백업[편집]

exp system/oracle 
full=y 
log=full_log.log 
file=/home/oracle/full_test001.dmp 

tablespaces=(example,undotbsl)

1.5 여러 사용자 백업[편집]

exp system/oracle 
file=/home/oracle/full_test001.dmp 
owner=(scott,tiger)

1.6 일부 테이블 백업[편집]

  • 버퍼 10메가
  • Direct Path
exp system/oracle 
full=y 
log=full_log.log 
file=/home/oracle/full_test001.dmp 
buffer=20140000 
direct=y 
tables=(example,undotbsl)

1.7 일반사용자로 Full Backup[편집]

    1. 권한확인
SELECT * 
  FROM DBA_ROLE_PRIVS 
 WHERE GRANTEE = 'SCOTT';
    1. 권한부여
GRANT EXP_FULL_DATABASE 
    TO SCOTT;
  • DBA권한을 부여 해도 됨(권장하지 않음)

1.8 파라메터를 이용하여 백업[편집]

exp system/oracle 
parfile=para_file.txt

- para_file.txt file=/data/test09.dmp full=y direct=y query="where job='xxx' and ... " ....

1.9 SQL적용하여 일부데이터만 백업[편집]

  • parfile 옵션을 사용하여 파라메터로 사용하면 편리
exp scott/tiger 
query=\"where ename like \'F%\'\"
tables=emp file =/data/emp.dmp

1.10 DBMS_DATAPUMP 패키지/프로시져 이용 EXPORT 백업[편집]

-- 1.테이블 DUMP EXPORT 스크립트
DECLARE
hdnl NUMBER;
v_open_date VARCHAR2(50) := '20200102'; -- 백업시간
v_job_name  VARCHAR2(50) := 'EXP_XXXWEB_OPEN'; -- 잡이름 

BEGIN

hdnl := DBMS_DATAPUMP.OPEN( operation => 'EXPORT', job_mode => 'SCHEMA', job_name=>v_job_name||'_'||v_open_date);

DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => v_job_name||'_'||v_open_date||'_01.EXP', directory => 'DATA_PUMP_DIR2', filetype => dbms_datapump.ku$_file_type_dump_file ,reusefile=>1);
DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => v_job_name||'_'||v_open_date||'_01.LOG', directory => 'DATA_PUMP_DIR2', filetype => dbms_datapump.ku$_file_type_log_file  ,reusefile=>1);

-- 스키마 정보
 DBMS_DATAPUMP.METADATA_FILTER(handle => hdnl,
                               name   => 'SCHEMA_EXPR',
                               value  => ' IN (''XXX'',''WEB'')'
                               );

DBMS_DATAPUMP.START_JOB(hdnl);
END;

2 IMPORT[편집]

⚠️주의

2.1 IMPORT 옵션[편집]

build 데이터 IMPORT 옵션
* userid
* buffer
* file
* show
* grants
* indexes
* rows
* full
* fromuser
* touser
* tables
* tablespaces
* recordlength
* inctype
* commit
* parfile

2.2 DB전체 입력[편집]

imp system/oracle 
full=y
log=full_log.log 
file=/home/oracle/full_test001.dmp

2.3 일부 사용자만 입력[편집]

imp system/oracle 
file=/home/oracle/full_test001.dmp 
fromuser=(scott,tiger) 
tables=test01 ignore=y

2.4 테이블 소유자를 변경하여 입력[편집]

imp system/oracle 
file=/home/oracle/full_test001.dmp 
fromuser=scott
touser=tiger 
ignore=y

2.5 DDL만 추출하기[편집]

  • show=y 옵션사용 방법 - 로그에 저장하여 ddl 편집
  • indexfile 옵션을 사용하는 방법
imp system/oracle 
file=/data/test02.dmp 
full=y 
show=y 
log=scott_ddl.sql

2.6 import 시 테이블과 index 분리[편집]

  • import시 indexes=n 옵션으로 import후 인덱스 별도 생성

2.7 인덱스 파일만 별도 추출[편집]

imp system/oracle 
file=/data/test02.dmp indexfile=scott_index.sql 
full=y

2.8 DB_LINK를 이용한 IMPORT[편집]

데이터펌프 IMPORT API