ORACLE/Back & Recovery

8장 데이터 이동하기

히드라야 2015. 4. 20. 10:43








※ 항상 OS 용량을 체크해줄것


http://shinb.tistory.com/15 클론 복제 


 

SQL> revoke read, write on directory datapump from system;


SQL> revoke create any  directory from system;




alter user 계정 identified by 암호 


[oracle@server113 exp]$ ls -lh


alter user system account unlock;





[temporary tablespace 용량, 경로 조회하기]


col tablespace_name for a10


col file_name for a50


select file_id, tablespace_name, bytes/1024/1024 MB, file_name from dba_temp_files ;




[temporary tablespace 생성하기]


create temporary tablespace temp2


tempfile '/app/oracle/oradata/testdb/temp02.dbf' size 10M


autoextend on;




[default tablespace 조회하기 ]


col property_name for a30


col property_value for a10


col description for a50


select * from database_properties                                        where property_name like 'DEFAULT_TEMP%' ;




[default tablespace 바꾸기]


alter database default temporary tablespace temp2;




[클론 한뒤]


ifconfig

setup

service network restart



① network를 nat로 바꿈 


② 2번째도 같은대역으로 바꾸어줌 






As-Is(기존의)     →     To-Be(새로운)  데이터를 옮기려고 할때 사용

exp/imp는 oracle 프로그램

open 상태에서만 사용가능 

export , import 할때는 반드시 같은 계정으로 수행 해줄것 

동작하고  있는 상태에서는 Stop 하는 경우 지금까지의 작업은 전부 cancel 됨 

export ↔ import 해야함 

export ↔ importpump 안됨 


◎export


바이너리 파일로 저장

시작 지점의 데이터를 옮기는것 (중간에 데이터의 변형이 일어나도 변경안됨)


종류


1 Conventional Path export:  Evaluation Buffer 에 옮겨 놓기 때문에 export 중에 데이터의 변경가능 

                              why : DB buffer cache는 정상 운영


2 Direct Path export  : export 중에 데이터를 바꾸는 것을 차단 

why: DB buffer cache에서 바로 옮기기 때문 


방법

1   데이터 베이스 전체를 export

2   특정 tablespace 를 export

3   owner 옵션 특정 스키마를 export = 사용자 별로 export 多

4  table 옵션을 사용해서 원하는 테이블만 옮길때 


※작업은 temporay tablespace 공간을 사용 → 큰데이터를 옮길때는 큰 temporary tablespace를 사용할것 



[Conventional Path로 Full export]


time exp system/oracle full=y file=/data2/exp/full01.dmp  log=/data2/exp/full_log01.log



[Direct Path로 Full export 받기]

time exp system/oracle full=y file=/data2/exp/full03.dmp log=/data2/exp/full_log03.log direct=y



[export를 저장하는 파일을 분할 받기]

[oracle@server113 exp]$ time exp system/oracle full=y file=/data2/exp/full03_1.dmp , /data2/exp/full03_2.dmp,  /data2/exp/full03_3.dmp filesize=40M

[특정 table space 만 export]
 time exp system/oracle file=/data2/exp/ex_users.dmp tablespaces=example,users

[특정 table만 export 하기]
 exp scott/tiger tables=emp, dept file=/data2/exp/emp_dept.dmp

[여러 사용자를 동시에 export 하기]
 time exp system/oracle file=/data2/exp/scott_hr.dmp owner=scott,hr

[parameter file 이용한 export]

vi full.dat
file=/data2/exp/full_par.dmp
full=y
direct=y

[oracle@server113 exp]$  exp system/oracle parfile=full.dat

[ 특정 조건을 통해 export 받기] = where 절만 줄 수 있음
$ exp scott/tiger query = \"where job=\'CLERK\' and sal\ \>1000\" file=/data2/exp/scott2.dmp tables=emp

[스키마 별로 자동 export 받는 스크립트]









◎import 


export 파일에 적혀있는 DDL, DML을 순차적으로 실행하는것 이때 Redo log, Undo Segment 


[전체 데이터 import 수행하기]

imp system/oracle file=/data2/exp/full11.dmp ignore=y full=y


[특정 사용자만 import 수행하기]

imp system/oracle file=/data2/exp/full11.dmp fromuser=scott


[scott 사용자의 test02 테이블을 hr사용자로 변경하기 ]


[실제 데이터는 import 하지 않고 DDL 문장만 추출하기]






◎ Data Pump 

export/import에 비해 향상된 유틸리티 

1 작업관리의 편의성

2 필요한 디스크 공간의 예측

3 원격지 DB에 작업 수행 가능 

4 remapping 기능 지원

5 dump 작업하면서 압축을 동시에 진행

6 빨라진 작업속도 



[사용전 환경 설정하기]


mkdir /data2/dp


SQL> create or replace directory datapump as '/data2/dp';


SQL> grant read, write on directory datapump to scott;


SQL> grant create any directory to scott;




[암호 틀린 애러]
UDE-01017: operation generated ORACLE error 1017
ORA-01017: invalid username/password; logon denied

☞ alter user 계정 identified by 암호


[계정이 lock 걸린 상황]
UDE-28000: operation generated ORACLE error 28000
ORA-28000: the account is locked

☞ alter user system account unlock;



ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation

☞ 경로는 지정 되었지만 폴더가 없는 상황, 해당 경로에 폴더를 생성





◎ extdp / impdp


중요 옵션 

① directory : 경로를 설정

② dumpfile : 이름을 지정 

③ compression : 압축 하기

④ job_name : 작업을 stop 하기 위해 이름 지정 

⑤ parallel : 프로세스가 여러개인 서버에서 운영할 때 사용 

⑥ Attach : 중단된 작업에 다시 접속할때 사용하는 파라미터 

kill_job  : 해당 작업을 삭제하기 

start_job: 중단된 작업 다시 실시

stop_job: 작업을 중단하기 




[job 조회 명령]

col owner_name for a10

col job_name for a10

col operation for a10

col job_mode for a10

select owner_name , job_name, operation , job_mode, state

from dba_datapump_jobs;



[Object owner 조회]

set line 200

col owner.object for a15

select o.status , o.object_id, o.object_type, o.owner||'.'||object_name "OWNER.OBJECT"

from dba_objects o, dba_datapump_jobs j

where o.owner=j.owner_name

and o.object_name=j.job_name

and j.job_name  NOT LIKE 'BIN$%'

ORDER BY 4,2;








[scott 계정의 emp, dept 테이블만 백업 받기]


expdp scott/tiger tables=emp,dept directory=datapump job_name=t1 dumpfile=emp_dept.dmp




[scott schema 전부 백업 받기]


time expdp scott/tiger schemas=scott directory=datapump   dumpfile=scott01.dmp





[DB 전체 백업 받기]


 time expdp system/oracle full=y directory=datapump dumpfile=full01.dmp job_name=a




[일시 중단 후 다시 작업하기]


 time expdp system/oracle full=y directory=datapump dumpfile=full01.dmp job_name=c



 expdp system/oracle attach=system.c


[비정상적으로 종료된 job 취소하기 ]


mkdir dp_a dp_b dp_c dp_d


SQL> create directory dp_a as '/data2/dp_a';


Directory created.


SQL> create directory dp_b as '/data2/dp_b';


Directory created.


SQL> create directory dp_c as '/data2/dp_c';

Directory created.

SQL> create directory dp_d as '/data2/dp_d';

Directory created.



SQL> grant read, write on directory dp_a to scott;


Grant succeeded.


SQL> grant read, write on directory dp_b to scott;


Grant succeeded.


SQL> grant read, write on directory dp_c to scott;


Grant succeeded.


SQL> grant read, write on directory dp_d to scott;


Grant succeeded.



expdp system/oracle full=y directory=dp_a                         dumpfile=full01.dmp job_name=dp_a

stop

yes

expdp system/oracle full=y directory=dp_b                        dumpfile=full02.dmp job_name=dp_b

stop

yes

expdp system/oracle full=y directory=dp_c                        dumpfile=full03.dmp job_name=dp_c

stop

yes


조회하기 

삭제

rm -f /data2/dp_a/*

rm -f /data2/dp_b/*

rm -f /data2/dp_c/*


expdp system/oracle attach=dp_a

expdp system/oracle attach=dp_b

expdp system/oracle attach=dp_c


ORA-39002: invalid operation

ORA-39000: bad dump file specification

ORA-31640: unable to open dump file "/data2/dp_c/full03.dmp" for read

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3



SQL> drop table system.dp_a;

Table dropped.

SQL> drop table system.dp_b;

Table dropped.


SQL> drop table system.dp_c;


Table dropped.




[여러 사용자 테이블 한꺼번에 expdp 받기]



expdp system/oracle directory=datapump                         dumpfile=sott16.dmp tables=scott.emp,hr.department



[병렬로 expde 작업하기]


 mkdir dir1 dir2 dir3 dir4


SQL> create or replace directory DATADIR1 as '/data2/dir1';


Directory created.


SQL> create or replace directory DATADIR2 as '/data2/dir2';


Directory created.


SQL> create or replace directory DATADIR3 as '/data2/dir3';


Directory created.


SQL> create or replace directory DATADIR4 as '/data2/dir4';


Directory created.


 expdp system/oracle full=y parallel=4                         

  dumpfile = DATADIR1:full1%U.dat                                   ,

DATADIR2:full2%U.dat,                                   

DATADIR3:full3%U.dat,                                   

DATADIR4:full4%U.dat                                    

filesize = 100M



[병렬로 위치를 분산하여 expde 작업하기] 




[파라미터 파일을 사용해서 expdp 수행 (여러개의 파일로 분할)]





[상위 버젼에서 하위버젼으로 데이터 이동하기 (개발→운영)] 







impdp

중요 옵션

① Table_exists_action

② Remap_schema

③ Remap_datafile

④ Remap_tablespace

⑤ Remap_table




[parameter 파일을 이용 impdp 작업]




impdp 병렬 작업하기]




[import 수행하지 않고 DDL 문장만 추출하기 ]



[설치된 경로 확인 하기 ]