반응형

1. Restore & Recovery

Restore : backup 받았던 파일을 복원 시키는 것 ( 백업된 후부터 망가지기 전까지의 데이터는 다 날아감 )

Recovery : 복원된 파일을 log file 을 적용시켜서 복구 하는 것 


복구 원리 : 1. rccover 명령 -> control file 정보 확인 -> data file 정보 확인 -> control file 과 data file 정보가 다를 경우 redo log 파일 또는 archived log file 의 정보를 적용시켜 복구 완료함


복구 명령어 : 1. recover database ;

 2. recover tablespace useres ;

       3. recover datafile '/app/oracle/oradata/testdb/users01.dbf' ;


< No Archive Log Mode >


2. 데이터 파일 일부 삭제된 후 복구하기 ( 노 아카이브 모드에서 복구 가능할 때, 리두로그에 남아있어서 )

장애 상황 : 현재 운영중인 DB 서버에서 누군가가 /app/oracle/oradata/testdb/users01.dbf 파일을 지운것을 확인했다.

    현재 운영중인 DB서버는 No Archive log mode이다. 이 경우 복구방법은 지워지기전 백업했던 데이터파일, 

    컨트롤파일, redo log file 까지 전부 복원 하는 것 뿐


- no archive mode  , db open 상태 -

SYS> !rm /app/oracle/oradata/testdb/users01.dbf


SYS> create table scott.tt100(no number) tablespace users ;

Table created


SYS> insert into scott.tt100 value(1) ;

1 row created.


SYS> commit ;


SYS> select * from scott.tt100 ;

NO

------

  1

SYS> alter system switch logfile ;


SYS> /


SYS> /


SYS> /

ERROR at line 1:

ORA-03113:end-of-file on communication channel

Process ID:7520

Session ID : 1 Serial number: 5


SYS> exit


[oracle@localhost ~]$ sqlplus sys/oracle as sysdba


SYS> startup      <-- 에러나서 mount 로 statup 됨


SYS> !cp /data/backup/close/users01.dbf /app/oracle/oradata/testdb/           <-- 백업파일을 다시 복원


SYS> recover tablespace users ;        <- users 복구

Media recovery complete 


SYS> alter database open ;



3. 삭제된 데이터파일을 복구하지않고 DB 시작하기 ( 노아카이브 모드에서 복구 불가능할 때, 아카이브 로그 없는 경우 )

장애상황 : No archive log mode 로 운영중인 데이터베이스에서 데이터파일이 하나 지워졌다.

               때마침 checkpoint 가 발생되어 운영중인 DB가 갑자기 강제 종료가 되어 버렸다.

               다시 접속해서 DB를 재 시작 시키려고 하니 지워진 파일 때문에 시작이 되지 않는다.

               다행히 데이터파일이 지워진 테이블스페이스는 중요한 자료가 없어서 삭제되어도 괜찮고

               빨리 DB 를 시작시켜야만 한다.

- no archive mode  , db open 상태 -

SYS> alter system switch logfile ; 


SYS> /        <- 여러번 로그스위치 해줌


SYS> !rm -rf /app/oracle/oradata/testdb/user01.dbf


SYS> create table scott.tt200(no number) tablespace users ;


SYS> insert into scott.tt200 values (2) ;


SYS> commit ;


SYS> select * from scott.tt200 ;

NO

------

  2


SYS> alter system switch logfile ;


SYS> /


SYS> /


SYS> shutdown immediate ;


SYS> startup


SYS> !cp /data/backup/close/users01.dbf /app/oracle/oradata/testdb/

recover tablespace users; 

ORA-00279: change 2206096 generated at 09/19/2013 05:07:44 needed for thread 1 

ORA-00289: suggestion : /data/arc2/6_1_812624262.arc 

ORA-00280: change 2206096 for thread 1 is in sequence #6 

 

 

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}  엔터 


에러발생


SYS> alter database datafile '/app/oracle/oradata/testdb/users01.dbf' offline drop ;


SYS> alter database open ;



4. 데이터 파일의 경로를 변경해서 복구하기

장애 상황 : Data file 이 있는 디렉토리의 손상으로 긴급히 다른 임시 디렉토리를 만들고 그 곳으로

                Data file 을 이동시키고 복원해야  합니다


파일 위치 : -data file : /data/temp 로 이동시키고 복구

                -control file , redo log file : /app/oracle/oradata/testdb/

                -backup file : /data/backup/close/


작업 순서 : 

1. DB 종료

2. /data/temp 디렉토리 생성해서 /data/backup/close/*.dbf 파일을 복사

3. /data/backup/close/*.log , *.ctl 을 /app/oracle/oradata/testdb 로 이동

4. 컨트롤 파일 내용 수정

5. DB 오픈

SYS> shutdown immediate ;

oracle $ mkdir /data/temp


oracle $ cp /data/backup/close/*.dbf /data/temp 로 복사


oracle $ cp /data/backup/close/*.ctl /app/oracle/oradata/testdb/


oracle $ cp /data/backup/close/*.log /app/oracle/oradata/testdb/


SYS> startup mount 


SYS> !cp /data/backup/close/*.dbf /app/oracle/oradata/testdb/          <-- data file 복원


SYS> alter database rename file '/app/oracle/oradata/testdb/system01.dbf   to '/data/temp/system01.dbf';

Database altered.


SYS> alter database rename file '/app/oracle/oradata/testdb/undotbs01.dbf  to '/data/temp/undotbs01.dbf';

Database altered.


SYS> alter database rename file '/app/oracle/oradata/testdb/sysaux01.dbf  to '/data/temp/sysaux01.dbf';

Database altered.


SYS> alter database rename file '/app/oracle/oradata/testdb/users01.dbf   to '/data/temp/users01.dbf';

Database altered.


SYS> alter database rename file '/app/oracle/oradata/testdb/example01.dbf  to '/data/temp/example01.dbf';

Database altered.


SYS> alter database open;

Database altered.


SYS> select tablespace_name,bytes/1024/1024 MB,file_name from dba_data_files;


TABLESPACE      MB            FILE_NAME

---------- ---------- -----------------------

USERS                   5          /data/temp/users01.dbf

SYSAUX              240         /data/temp/sysaux01.dbf

UNDOTBS1           35         /data/temp/undotbs01.dbf

SYSTEM              480         /data/temp/system01.dbf

EXAMPLE            100         /data/temp/example01.dbf



< Archive Log Mode - 완전 복구>


아카이브 로그 파일을 이용해서 백업파일에서 장애 난 파일 까지의 데이터를 완전하게 복구 할 수 있다.


실습전 archive 모드로 변경 해주고 파일 다시 백업. 실습을 위해 test2 tablespace 생성해줌

SYS> alter database archivelog ;


SYS> create tablespace test2

  2    datafile '/app/oracle/oradata/testdb/test02.dbf' size 5M ;


SYS> shutdown immediate ;


SYS> !cp /app/oracle/oradata/testdb/* /data/backup/close/ 

1. offline 되는 tablespace 장애 복구


SYS> startup


SYS> create table scott.tt750 (no number) tablespace test2 ;


SYS> insert into scott.tt750 values (1) ;


SYS> commit ;


SYS> select * from secott.tt750 ;

NO

---

  1


SYS> !rm /app/oracle/oradata/testdb/test02.dbf


SYS> alter tablespace test2 offline ;


SYS> alter tablespace test2 online ;

*

ERROR at line 1:

ORA-011547: cannot identify/loca data file 6 - see DBWR trace file

ORA-01110: data file 6 : '/app/oracle/oradata/testdb/test02.dbf'


SYS> !cp /data/backup/close/test02.dbf /app/oracle/oradata/testdb/


SYS> alter tablerspace test2 online ;

*

ERROR at line 1:

ORA-01113: file 6 needs media recovery

ORA-01110: data file 6: '/app/oracle/oradata/testdb/test02.dbf'


백업 파일을 복원했는데 online 안되고 복구하라는 에러 메세지가 나옴


SYS> recover tablespace test2;

Media recovery complete.


SYS> alter tablespace test2 online;


Tablespace altered.


SQL> select * from scott.tt750;


        NO

----------

         1


OFFLINE 되는 Tablespace 는 DB 종료없이 해당 Tablespace 만 offline 하고 복구하면 됨


2. offline 안되는 tablespace 장애 복구


SQL> create table scott.tt800 (no number) tablespace system;


Table created.


SQL> insert into scott.tt800 values(2);


1 row created.


SQL> commit;


Commit complete.


SQL> select * from scott.tt800;


        NO

----------

         2


SQL> !rm /app/oracle/oradata/testdb/system01.dbf


SQL> altert tablespace system offline;

SP2-0734: unknown command beginning "altert tab..." - rest of line ignored.

SQL> alter tablespace system offline;

alter tablespace system offline

*

ERROR at line 1:

ORA-01541: system tablespace cannot be brought offline; shut down if necessary



SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.


SQL> startup

ORACLE instance started.


Total System Global Area  422670336 bytes

Fixed Size                  1344616 bytes

Variable Size             293604248 bytes

Database Buffers          121634816 bytes

Redo Buffers                6086656 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 1 - see DBWR trace file

ORA-01110: data file 1: '/app/oracle/oradata/testdb/system01.dbf'



SQL> !cp /data/backup/close/system01.dbf /app/oracle/oradata/testdb/


SQL> recover tablespace system;

Media recovery complete.


SQL> alter database open;


Database altered.


SQL> select * from scott.tt800;


        NO

----------

         2



3. 백업파일이 없는 상태에서 복구

SQL> @dd


TABLESPACE_NAME              MB         FILE_NAME

--------------------   ------    ----------------------------------------

TEST2                                   5              /app/oracle/oradata/testdb/test02.dbf                    <--파일삭제

EXAMPLE                        345.625           /app/oracle/oradata/testdb/example01.dbf

USERS                               7.5              /app/oracle/oradata/testdb/users01.dbf

UNDOTBS1                         265             /app/oracle/oradata/testdb/undotbs01.dbf

SYSAUX                             570             /app/oracle/oradata/testdb/sysaux01.dbf

SYSTEM                             710             /app/oracle/oradata/testdb/system01.dbf



6 rows selected.


SQL> !rm -f /app/oracle/oradata/testdb/test02.dbf


SQL> create table scott.tt810 ( no number) tablespace test2;


Table created.


SQL> insert into scott.tt810 values (1);


1 row created.


SQL> commit;


Commit complete.


SQL> alter tablespace test2 offline;


Tablespace altered.


SQL> alter tablespace test2 online;

alter tablespace test2 online

*

ERROR at line 1:

ORA-01157: cannot identify/lock data file 6 - see DBWR trace file

ORA-01110: data file 6: '/app/oracle/oradata/testdb/test02.dbf'



SQL> @dd


TABLESPACE_NAME              MB         FILE_NAME

--------------------   ------    ----------------------------------------

TEST2                                                   /app/oracle/oradata/testdb/test02.dbf                   

EXAMPLE                        345.625           /app/oracle/oradata/testdb/example01.dbf

USERS                               7.5              /app/oracle/oradata/testdb/users01.dbf

UNDOTBS1                         265             /app/oracle/oradata/testdb/undotbs01.dbf

SYSAUX                             570             /app/oracle/oradata/testdb/sysaux01.dbf

SYSTEM                             710             /app/oracle/oradata/testdb/system01.dbf


6 rows selected.


SQL> alter database create datafile

  2  '/app/oracle/oradata/testdb/test02.dbf'       <--삭제 전 원래 경로

  3  as '/home/oracle/test01.dbf';                     <-- 새로 만들어질 경로와 이름


Database altered.


SQL> recover tablespace test2;

Media recovery complete.

SQL> alter tablespace test2 open;

alter tablespace test2 open

                       *

ERROR at line 1:

ORA-02142: missing or invalid ALTER TABLESPACE option



SQL> alter tablespace test2 online;


Tablespace altered.


SQL> select * from scott.tt810;


        NO

----------

         1



반응형

'오라클 > 백업/복구' 카테고리의 다른 글

Redo log flle 장애 처리방법  (0) 2014.11.05
Log Miner 활용하기  (0) 2014.11.05
control file, data file 연습문제  (0) 2014.11.04
Control file 복구  (0) 2014.11.04
Data file Recovery (불완전 복구)  (0) 2014.11.04
Backup (cold, hot)  (0) 2014.10.30
사용자 암호설정/ Archive log mode, No Archive log mode  (0) 2014.10.29

+ Recent posts