목차
- FULL BACKUP + ARCH 복구
- FULL BACKUP 복구
- ARCH 복구
※ 모든 복구는 다른 데이터베이스에서 복구하는 상황을 가정한다.
복구를 위해 사전에 init.ora 파일 세팅해둘것
vi $ORACLE_HOME/dbs/initTESTDB.ora
1. FULL BACKUP + ARCH 복구
192.168.4.41 (TESTDB) -> VM (TESTDB)
이름은 동일하게 맞춰준다.
RMAN으로 FULL BACKUP을 해주고
추가로 데이터를 쌓은 뒤
ARCHIVED LOG FILE은 파일 자체를 복사해왔다.
복구 과정은 VM C7 (스테이지DB) 에서만 진행된다.
- profile 설정 변경
. ./.profile
혹은
export ORACLE_SID=TESTDB
export ORACLE_UNQNAME=TESTDB
※ cp .profile .profile_210729 / cp .profile .profile_orcl 와 같은 방식으로 기존 profile 파일은 보존되도록 한다.
기존 vm에 있던 db 이름은 ORCL
ORACLE_SID, ORACLE_UNQNAME를 바꿔준다 (ORCL -> TESTDB)
[root@vc7-19 ~]# su - oracle
Last login: Thu Jul 29 03:48:01 EDT 2021 on pts/0
(ORCL)/oracle/app/oracle/product/192> cd
(ORCL)/oracle/app/oracle/product/192> cp .profile .profile_orcl
(ORCL)/oracle/app/oracle/product/192> vi .profile
...
(ORCL)/oracle/app/oracle/product/192> . ./.profile
(TESTDB)/oracle/app/oracle/product/192>
VM C7(스테이지DB) 에서
OS oracle 계정으로 접속
(TESTDB)/oracle/app/oracle/product/192> rman target /
@ dbid = 실DB(RMAN 백업을 받은 DB) 에서 SELECT * FROM V$DATABASE 에서 DBID 조회
RMAN> set dbid=2858064844
executing command : SET DBID
-- set requested point in time
복구할 시점 지정 --> 언제 시점으로 복구해주세요
RMAN> SET UNTIL TIME "TO_DATE('2021/07/27 01:00:00','YYYY/MM/DD HH24:MI:SS')";
executing command : SET until clause
NOMOUNT로 STARTUP
RMAN> startup nomount
컨트롤 파일 복원
복원하기 전에 컨트롤 파일이 위치할 폴더를 생성해준다.
(TESTDB)/oracle/app/oracle/product/192> cd /ORADATA
(TESTDB)/ORADATA> mkdir TESTDB
## 권한 확인 해주기
(TESTDB)/ORADATA> ls -al
total 0
drwxr-xr-x. 4 oracle dba 33 Jul 29 02:59 .
dr-xr-xr-x. 21 root root 277 Jul 8 23:42 ..
drwxr-x---. 2 oracle dba 200 Jun 30 04:58 ORCL
drwxr-xr-x. 2 oracle dba 237 Jul 29 03:33 TESTDB
RMAN> restore controlfile from '/oracle/app/oracle/rman/db_ctl_c-2858064844-20210727-02';
MOUNT 상태로 변경
RMAN> alter database mount;
released channel : ORA_DISK_1
Statement processed
DB 복원
RMAN> restore database;
DB 복구 시도
RMAN> recover database;
-- 오류 발생
아카이브 로그 파일을 찾을 수 없다. 아카이브 로그 파일을 원래 설정된 경로인 /ARCH가 아니라, rman 백업한 곳에 같이 두었었다. 탐색해서 찾게 해줌
RMAN> catalog start with '/oracle/app/oracle/rman';
다시 시도
RMAN> recover database;
마지막 오류는 다음 아카이브 로그 파일(89번)이 없다는것
원래 생성된 아카이브로그파일이 88번까지였다. 복구 완료
데이터베이스 오픈
RMAN> alter database open resetlogs;
Statement processed
확인
RMAN> list incarnation;
rman_recovery.sh
#!/bin/bash
# rman_recovery.sh
# ORACLE RMAN BACKUP
############################################################
# ORACLE ENVIRONMENT SETTING :
############################################################
export ORACLE_SID=TESTDB
export ORACLE_UNQNAME=TESTDB
#export ORACLE_BASE=/oracle/app/oracle
#export ORACLE_HOME=/oracle/app/oracle/product/192
############################################################
# PATH SETTING :
############################################################
export BKDIR=/oracle/app/oracle/rman
export BKDIROLD=/oracle/app/oracle/rman_old
mkdir -p /oracle/app/oracle/rman
mkdir -p /oracle/app/oracle/rman_old
export date=`date '+%Y%m%d%H%M'`
mv $BKDIR/rman_recovery_*.log $BKDIROLD/
rman target / << EOF >> $BKDIR/rman_recovery_$date.log
run
{
set dbid=2858064844
SET UNTIL TIME "TO_DATE('2021/07/27 01:00:00','YYYY/MM/DD HH24:MI:SS')";
startup nomount
restore controlfile from '$BKDIR/db_ctl_c-2858064844-20210727-02';
alter database mount;
restore database;
catalog start with '$BKDIR';
recover database;
alter database open resetlogs;
list incarnation;
}
quit;
EOF
echo "Rman Recovery End Time : `date` ------------------------ End "
echo "Rman Recovery End Time : `date` ------------------------ End " >> $BKDIR/rman_recovery_$date.log
2. 기존에 백업받았던 RMAN FULL 백업본 복구
: TESTDB(192.168.4.41) --> VM C7 으로
: ARCH 적용 X
ARCHIVED LOG FILE은 적용하지 않고 FULL BACKUP본만 복구
기존엔 RESTORE 단계 이후 RECOVERY까지 해주었으나, 이 상황에선 다름
Restore(복원)
- DB를 복구하는 과정에서 백업한 파일로부터 물리적인 파일을 적절한 위치로 복사하는 과정
- 백업이 존재하는 한 시점으로 데이터베이스를 돌려놓는다.
- 해당 상태에서는 복구 과정이 모두 끝난게 아니기 때문에 데이터베이스를 open 할 수 없다.
Recovery(복구)
- Restore로 DB를 특정 시점으로 돌려놓은 상태에서 백업해둔 Archive log를 적용해서, 과거에 백업이 끝났을 때의 시점으로 DB를 완벽하게 복구하는 과정
- RESTORE + ARCHIVE적용
=> RESTORE 이후 DATABASE OPEN을 해준다.
복구 과정
- profile 설정 변경
. ./.profile
혹은
export ORACLE_SID=TESTDB
export ORACLE_UNQNAME=TESTDB
※ cp .profile .profile_210729 / cp .profile .profile_orcl 와 같은 방식으로 기존 profile 파일은 보존되도록 한다.
기존 vm에 있던 db 이름은 ORCL
ORACLE_SID, ORACLE_UNQNAME를 바꿔준다 (ORCL -> TESTDB)
[root@vc7-19 ~]# su - oracle
Last login: Thu Jul 29 03:48:01 EDT 2021 on pts/0
(ORCL)/oracle/app/oracle/product/192> cd
(ORCL)/oracle/app/oracle/product/192> cp .profile .profile_orcl
(ORCL)/oracle/app/oracle/product/192> vi .profile
...
(ORCL)/oracle/app/oracle/product/192> . ./.profile
(TESTDB)/oracle/app/oracle/product/192>
@ dbid = 실DB(RMAN 백업을 받은 DB) 에서 SELECT * FROM V$DATABASE 에서 DBID 조회
(TESTDB)/oracle/app/oracle/product/192> rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Mon Aug 2 19:58:27 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> set dbid=2858064844
executing command: SET DBID
RMAN> startup nomount
Oracle instance started
Total System Global Area 2466249672 bytes
Fixed Size 8899528 bytes
Variable Size 536870912 bytes
Database Buffers 1912602624 bytes
Redo Buffers 7876608 bytes
RMAN>
컨트롤 파일 복원
복원하기 전에 컨트롤 파일이 위치할 폴더를 생성해준다.
(TESTDB)/oracle/app/oracle/product/192> cd /ORADATA
(TESTDB)/ORADATA> mkdir TESTDB
## 권한 확인 해주기
(TESTDB)/ORADATA> ls -al
total 0
drwxr-xr-x. 4 oracle dba 33 Jul 29 02:59 .
dr-xr-xr-x. 21 root root 277 Jul 8 23:42 ..
drwxr-x---. 2 oracle dba 200 Jun 30 04:58 ORCL
drwxr-xr-x. 2 oracle dba 237 Jul 29 03:33 TESTDB
@ dbid = 실DB(RMAN 백업을 받은 DB) 에서 SELECT * FROM V$DATABASE 에서 DBID 조회
RMAN> restore controlfile from '/oracle/app/oracle/rman/db_ctl_c-2858064844-20210727-02';
Starting restore at 02-AUG-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=33 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/ORADATA/TESTDB/control01.ctl
output file name=/ORADATA/TESTDB/control02.ctl
Finished restore at 02-AUG-21
RMAN> alter database mount;
released channel: ORA_DISK_1
Statement processed
RMAN> restore database;
Starting restore at 02-AUG-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=39 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /ORADATA/TESTDB/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /ORADATA/TESTDB/users02.dbf
channel ORA_DISK_1: restoring datafile 00003 to /ORADATA/TESTDB/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /ORADATA/TESTDB/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /ORADATA/TESTDB/users01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/oracle/rman/data_0n051j97_1_1_20210727
channel ORA_DISK_1: piece handle=/oracle/app/oracle/rman/data_0n051j97_1_1_20210727 tag=TAG20210727T203343
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 02-AUG-21
RMAN> alter database open resetlogs;
Statement processed
RMAN>
rman_recovery.sh
#!/bin/bash
# rman_recovery.sh
# ORACLE RMAN BACKUP
# FULL BACKUP WITHOUT ARCHIVED LOGS
############################################################
# ORACLE ENVIRONMENT SETTING :
############################################################
export ORACLE_SID=TESTDB
export ORACLE_UNQNAME=TESTDB
#export ORACLE_BASE=/oracle/app/oracle
############################################################
# PATH SETTING :
############################################################
export BKDIR=/oracle/app/oracle/rman
export BKDIROLD=/oracle/app/oracle/rman_old
mkdir -p /oracle/app/oracle/rman
mkdir -p /oracle/app/oracle/rman_old
export date=`date '+%Y%m%d%H%M'`
mv $BKDIR/rman_recovery_*.log $BKDIROLD/
rman target / << EOF >> $BKDIR/rman_recovery_$date.log
run
{
set dbid=2858064844
startup nomount
restore controlfile from '$BKDIR/db_ctl_c-2858064844-20210727-02';
alter database mount;
alter database open resetlogs;
}
quit;
EOF
echo "Rman Recovery End Time : `date` ------------------------ End " >> $BKDIR/rman_recovery_$date.log
3. ARCH 파일을 이용한 순차적 복구
: ARCH 파일 단위, 시점 단위 (until 날짜지정)
RMAN FULL 백업본 복구 이후 진행
-- 시점 단위
# 실행중이던 DB shutdown 후 진행
...
startup mount
set autorecovery on
recover database until time '2007-08-17:09:37:26' --> mount 단계에서 사용
...
alter database open resetlogs;
https://dinggur.tistory.com/151
-- 파일 단위
cancel로 입력을 받아 취소될때까지 복구
# 실행중이던 DB shutdown 후 진행
...
startup mount
recover database until cancel
alter database open resetlogs;
########################## Arch 파일 단위 복구
RMAN> shutdown immediate
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 2466249672 bytes
Fixed Size 8899528 bytes
Variable Size 536870912 bytes
Database Buffers 1912602624 bytes
Redo Buffers 7876608 bytes
RMAN> exit
Recovery Manager complete.
(TESTDB)/oracle/app/oracle/product/192> sqlplus /nolog
SQL*Plus: Release 19.0.0.0.0 - Production on Mon Aug 2 21:47:27 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 5887532 generated at 07/27/2021 19:55:07 needed for thread 1
ORA-00289: suggestion : /ARCH/1_84_1074736718.arc
ORA-00280: change 5887532 for thread 1 is in sequence #84
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/ARCH/84_1_1074736718.arc
ORA-00279: change 5896117 generated at 07/27/2021 21:32:16 needed for thread 1
ORA-00289: suggestion : /ARCH/1_85_1074736718.arc
ORA-00280: change 5896117 for thread 1 is in sequence #85
ORA-00278: log file '/ARCH/84_1_1074736718.arc' no longer needed for this
recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/ARCH/85_1_1074736718.arc
ORA-00279: change 5896380 generated at 07/27/2021 21:33:46 needed for thread 1
ORA-00289: suggestion : /ARCH/1_86_1074736718.arc
ORA-00280: change 5896380 for thread 1 is in sequence #86
ORA-00278: log file '/ARCH/85_1_1074736718.arc' no longer needed for this
recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/ARCH/86_1_1074736718.arc
ORA-00279: change 5897135 generated at 07/27/2021 21:35:14 needed for thread 1
ORA-00289: suggestion : /ARCH/1_87_1074736718.arc
ORA-00280: change 5897135 for thread 1 is in sequence #87
ORA-00278: log file '/ARCH/86_1_1074736718.arc' no longer needed for this
recovery
SQL> alter database open resetlogs;
Database altered.
########################## 데이터 확인
SQL> select count(*) from TEST.DUMMY_1;
COUNT(*)
----------
6000000
SQL> select count(*) from TEST.DUMMY_4;
COUNT(*)
----------
7000000
########################## Arch 파일 시점 단위 복구
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 2466249672 bytes
Fixed Size 8899528 bytes
Variable Size 536870912 bytes
Database Buffers 1912602624 bytes
Redo Buffers 7876608 bytes
Database mounted.
SQL> set autorecovery on
SQL> recover database until time '2021-07-28:09:00:00'
Media recovery complete.
SQL> alter database open resetlogs;
Database altered.
########################## 데이터 확인
SQL> select count(*) from TEST.DUMMY_1;
COUNT(*)
----------
6000000
SQL> select count(*) from TEST.DUMMY_4;
COUNT(*)
----------
7000000
SQL>
SELECT *
FROM V$INSTANCE;
'Dev > Oracle' 카테고리의 다른 글
[Oracle] 인덱스 구조 (0) | 2022.06.21 |
---|---|
[Oracle] 복구한 DB 원복 (0) | 2022.06.20 |
[Oracle] RMAN Backup (0) | 2022.06.17 |
[Oracle] 조인 정리 (0) | 2022.06.16 |
[Oracle] 대기 이벤트 (0) | 2022.06.15 |
댓글