rman 완전복구, 불완전복구
1. 사용 안함 설정 -> offline, shutdown
2. 백업 복원 -> restore
3. 복구 -> recover
4. 사용함 -> online, open
Restore - 백업 파일로부터의 복원
Recover - Redo Log/Archive Log 적용시켜 복구
#완전복구
1) offline 가능한 data file 삭제 복구 작업
2) offline 불가능한 data file 삭제 복구 작업
3) 임시경로 생성하여 복구
4) 필요한 datafile 만 복구
# 불완전 복구 ( 불완전복구는 패스 : 하는방법만 숙지 )
장애난 시간을 찾아 그시간을 복구 후. resetlogs, open 방식
1) drop table 복구
2) Drop table 복구 - 임시 경로 사용
3) Drop table 복구 - 증분 백업 파일 활용
4) Drop tablespace 복구하기
1) offline 가능한 data file 삭제 복구 작업
-----------------
백업 (USERS tbs)
-------------------------
MAN> run {
allocate channel c1 device type disk;
backup as compressed backupset
tablespace users channel c1
format '/home/oracle/backup/USER%u_%t';
}
Starting backup at 28-MAR-16
channel c1: starting compressed full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel c1: starting piece 1 at 28-MAR-16
channel c1: finished piece 1 at 28-MAR-16
piece handle=/home/oracle/backup/USER06r1jnei_907664850 tag=TAG20160328T090730 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:15
Finished backup at 28-MAR-16
released channel: c1
-------------------------
장애. users dbf 삭제
-------------------------
SYS@ORCL AS SYSDBA> !rm -rf /u01/app/oracle/oradata/orcl/users01.dbf
SYS@ORCL AS SYSDBA>
SYS@ORCL AS SYSDBA>
SYS@ORCL AS SYSDBA> !ls /u01/app/oracle/oradata/orcl/users01.dbf
ls: cannot access /u01/app/oracle/oradata/orcl/users01.dbf: No such file or directory
-------------------------
복구
1) 해당 tbs offline
2) restore (백업사용). recover (Redo Log/Archive Log 복구)
3) online
-------------------------
RMAN> sql 'alter tablespace users offline immediate';
sql statement: alter tablespace users offline immediate
SYS@ORCL AS SYSDBA> select STATUS ,name FROM V$DATAFILE where STATUS='OFFLINE';
STATUS OFFLINE
------- --------------------------------------------------------------------------------
NAME /u01/app/oracle/oradata/orcl/users01.dbf
RMAN> restore tablespace users;
Starting restore at 28-MAR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 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 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/USER06r1jnei_907664850
channel ORA_DISK_1: piece handle=/home/oracle/backup/USER06r1jnei_907664850 tag=TAG20160328T090730
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 28-MAR-16
RMAN>
RMAN> recover tablespace users;
RMAN> SQL 'alter tablespace users online';
sql statement: alter tablespace users online
SYS@ORCL AS SYSDBA> !ls /u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
2) offline 불가능한 data file 삭제 복구 작업
-------------------------
백업(SYSTEM)
-------------------------
run {
allocate channel c1 device type disk;
backup as compressed backupset
tablespace SYSTEM channel c1
format '/home/oracle/backup/SYSTEM%u_%t';
}
-------------------------
장애
system dbf 삭제
-------------------------
SYS@ORCL AS SYSDBA> !rm -rf /u01/app/oracle/oradata/orcl/system01.dbf
SYS@ORCL AS SYSDBA> !ls /u01/app/oracle/oradata/orcl/system01.dbf
ls: cannot access /u01/app/oracle/oradata/orcl/system01.dbf: No such file or directory
-------------------------
복구
1. shutdown (offline 불가능)
2. mount
3. restore, recover
4. alter database open
-------------------------
run{
startup mount;
restore tablespace system;
recover tablespace system;
alter database open;
}
RMAN> run{
2> startup mount;
3> restore tablespace system;
4> recover tablespace system;
5> alter database open;
6> }
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 3290345472 bytes
Fixed Size 2217832 bytes
Variable Size 3187673240 bytes
Database Buffers 83886080 bytes
Redo Buffers 16568320 bytes
Starting restore at 28-MAR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 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 /u01/app/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/SYSTEM07r1jo35_907665509
channel ORA_DISK_1: piece handle=/home/oracle/backup/SYSTEM07r1jo35_907665509 tag=TAG20160328T091829
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 28-MAR-16
Starting recover at 28-MAR-16
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 28-MAR-16
database opened
SYS@ORCL AS SYSDBA> select status from v$instance;
STATUS
------------
OPEN
3) 임시경로 생성하여 복구
------------------------
장애
users dbf 삭제
-----------------------
SYS@ORCL AS SYSDBA> !rm -rf /u01/app/oracle/oradata/orcl/users01.dbf
SYS@ORCL AS SYSDBA> !ls /u01/app/oracle/oradata/orcl/users01.dbf
ls: cannot access /u01/app/oracle/oradata/orcl/users01.dbf: No such file or directory
------------------------
장애
users 파일번호 확인(4 번)
-----------------------
RMAN> report schema;
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 1000 SYSTEM *** /u01/app/oracle/oradata/orcl/system01.dbf
2 1500 SYSAUX *** /u01/app/oracle/oradata/orcl/sysaux01.dbf
3 1000 UNDOTBS1 *** /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 365 USERS *** /u01/app/oracle/oradata/orcl/users01.dbf
5 0 EXAMPLE *** /u01/app/oracle/product/11.2.0/dbs/MISSING00005
6 100 TBS_A *** /u01/app/oracle/oradata/orcl/tbs_a_01.dbf
7 100 TBS_A *** /u01/app/oracle/oradata/orcl/tbs_a_02.dbf
8 50 TBS_B *** /u01/app/oracle/oradata/orcl/tbs_b_01.dbf
9 85 UNDOTBS2 *** /u01/app/oracle/oradata/orcl/undotbs02.dbf
10 85 UNDOTBS2 *** /u01/app/oracle/oradata/orcl/undotbs02_2.dbf
11 100 TBS_C *** /u01/app/oracle/oradata/orcl/tbs_c_01.dbf
12 79 TBS_D *** /u01/app/oracle/oradata/orcl/tbs_d_01.dbf
13 10 TBS_RMAN *** /u01/app/oracle/oradata/orcl/TBS_RAMN01.dbf
14 100 PBJ_TEMP *** /u01/app/oracle/oradata/orcl/pbj_temp01.dbf
15 5 TBS_TEST *** /u01/app/oracle/oradata/orcl/TBS_TEST02.dbf
17 100 DATA01 *** /u01/app/oracle/oradata/orcl/DATA01.dbf
21 200 TBS_SCOTT_IDX *** /u01/app/oracle/oradata/orcl/scott_idx01.dbf
25 100 TBS_TEST *** /u01/app/oracle/oradata/orcl/TBS_TEST01.dbf
26 10 RC_TBS01 *** /u01/app/oracle/oradata/orcl/rc_tbs.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 500 TEMP 500 /u01/app/oracle/oradata/orcl/temp01.dbf
------------------------
복구.
1) users 파일번호 확인
2) offline
3) rename 하여 임시경로에 dbf 파일 생성
4) restore (백업파일로부터 복원)
5) swich 작업 ( alter database rename 작업과 동일. 복원 후 control file 의 내용을 바꿔주기 위함)
6) recover
7) online
-----------------------
run {
sql 'alter tablespace users offline immediate';
set newname for datafile '/u01/app/oracle/oradata/orcl/users01.dbf'
to '/home/oracle/users01.dbf';
restore tablespace users;
switch datafile 4;
recover tablespace users;
sql 'alter tablespace users online';
}
sql statement: alter tablespace users offline immediate
executing command: SET NEWNAME
Starting restore at 28-MAR-16
using channel ORA_DISK_1
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 00004 to /home/oracle/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/USER06r1jnei_907664850
channel ORA_DISK_1: piece handle=/home/oracle/backup/USER06r1jnei_907664850 tag=TAG20160328T090730
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 28-MAR-16
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=907666247 file name=/home/oracle/users01.dbf
Starting recover at 28-MAR-16
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 28-MAR-16
sql statement: alter tablespace users online
RMAN> report schema;
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 1000 SYSTEM *** /u01/app/oracle/oradata/orcl/system01.dbf
2 1500 SYSAUX *** /u01/app/oracle/oradata/orcl/sysaux01.dbf
3 1000 UNDOTBS1 *** /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 365 USERS *** /home/oracle/users01.dbf
4) 필요한 datafile 만 복원 후 복구
모든 데이터 파일을 복원하지 않고
반드시 복구에 필요한 데이터 파일만 복원 후 복구 (system, sysaux, undotbs, 해당데이터가들어있는 datafile)
복구에 필요없는 파일은 RMAN에서 offline 처리 후
restore, recover 과정에서 skip 옵션을 사용해 복원, 복구 하지 않도록 설정
순서
1) control file이랑 redo log file 최근에 쓰던 것을 임시 경로로 복사
2) 파라미터파일에서 controlfile 경로 변경
3) alter database rename을 통해 redo log file 경로 변경
4) 복원 경로를 다른 위치로 지정
5) 필요없는 데이터파일 drop
6) 백업파일 없는 데이터파일 생성
7) 필요없는 데이터파일 restore skip 해주기
8) alter database open ;
single quotation, double quotation 실수하기 쉬움!
alter 명령어는 " " double 로 묶어줘야 함
run {
2> sql "alter database rename file ''/data2/vol3/redo01_a.log''
3> to ''/data/temp/redo01_a.log''" ;
4> sql "alter database rename file ''/data2/vol3/redo02_a.log''
5> to ''/data/temp/redo02_a.log''" ;
6> sql "alter database rename file ''/data2/vol3/redo03_a.log''
7> to ''/data/temp/redo03_a.log''" ;
8> sql "alter database rename file ''/data2/vol5/redo01_c.log''
9> to ''/data/temp/redo01_c.log''" ;
10> sql "alter database rename file ''/data2/vol5/redo02_c.log''
11> to ''/data/temp/redo02_c.log''" ;
12> sql "alter database rename file ''/data2/vol5/redo03_c.log''
13> to ''/data/temp/redo03_c.log''" ;
14> set newname for datafile 1 to '/data/temp/system01.dbf' ;
15> set newname for datafile 2 to '/data/temp/sysaux01.dbf' ;
16> set newname for datafile 3 to '/data/temp/undotbs01.dbf' ;
17> sql "alter database datafile ''/data2/vol1/example01.dbf'' offline drop" ;
18> sql "alter database datafile ''/data/temp/users01.dbf'' offline drop" ;
19> sql "alter database create datafile ''/data2/vol2/test01.dbf''
20> as ''/data/temp/test01.dbf''" ;
21> restore database skip tablespace 'users','example' ;
22> switch datafile all ;
23> recover database skip tablespace 'users','example' ;
24> alter database open ;
25> }
# 불안전 복구
장애난 시간을 찾아 그시간을 복구 후. resetlogs, open 방식
1) drop table 복구
run {
shutdown immediate ;
startup mount ;
sql 'alter session set nls_date_format="YYYY-MM-DD:HH24:MI:SS"' ;
set until time='시간' ;
restore database ;
recover database ;
alter database open resetlogs ;
}
* sql 'alter session set nls_date_format="YYYY-MM-DD:HH24:MI:SS"' ; 하는 이유
시간 포맷을 마추기 위함.
.bash_profile에 입력하면 안해두됨
export NLS_DATE_FORMAT='YYYY-MM-DD:HH24:MI:SS'
2) Drop table 복구 - 임시 경로 사용
필요한 파일만 복원하고 나머지는 복원하지 않음.
ctl, redo 현재 쓰고 있는 것을 사용하여 rename 필요.
run {
2> sql "alter database rename file ''/data2/vol3/redo01_a.log''
3> to ''/data/temp/redo01_a.log''";
4> sql "alter database rename file ''/data2/vol3/redo02_a.log''
5> to ''/data/temp/redo02_a.log''";
6> sql "alter database rename file ''/data2/vol3/redo03_a.log''
7> to ''/data/temp/redo03_a.log''";
8> sql "alter database rename file ''/data2/vol5/redo01_c.log''
9> to ''/data/temp/redo01_c.log''";
10> sql "alter database rename file ''/data2/vol5/redo02_c.log''
11> to ''/data/temp/redo02_c.log''";
12> sql "alter database rename file ''/data2/vol5/redo03_c.log''
13> to ''/data/temp/redo03_c.log''";
15> set newname for datafile 1 to '/data/temp/system01.dbf' ;
16> set newname for datafile 2 to '/data/temp/sysaux01.dbf' ;
17> set newname for datafile 3 to '/data/temp/undotbs01.dbf' ;
18> set newname for datafile 5 to '/data/temp/example01.dbf' ;
19> sql "alter database datafile ''/data2/vol1/users01.dbf'' offline drop" ;
21> restore database skip tablespace 'users' ;
22> switch datafile all ;
24> sql 'alter session set nls_date_format="YYYY-MM-DD:HH24:MI:SS"' ;
25> set until time='2013-02-19:09:57:57' ;
27> recover database skip tablespace 'users' ;
28> alter database open resetlogs ;
29> }
3) Drop table 복구 - 증분 백업 파일 활용
RMAN> run {
2> startup mount ;
3> sql "alter database rename file ''/data2/vol3/redo01_a.log'' to ''/data/temp/redo01_a.log''";
4> sql "alter database rename file ''/data2/vol3/redo02_a.log'' to ''/data/temp/redo02_a.log''";
5> sql "alter database rename file ''/data2/vol3/redo03_a.log'' to ''/data/temp/redo03_a.log''";
6> sql "alter database rename file ''/data2/vol5/redo01_c.log'' to ''/data/temp/redo01_c.log''";
7> sql "alter database rename file ''/data2/vol5/redo02_c.log'' to ''/data/temp/redo02_c.log''";
8> sql "alter database rename file ''/data2/vol5/redo03_c.log'' to ''/data/temp/redo03_c.log''";
10> set newname for datafile 1 to '/data/temp/system01.dbf' ;
11> set newname for datafile 2 to '/data/temp/sysaux01.dbf' ;
12> set newname for datafile 3 to '/data/temp/undotbs01.dbf' ;
13> set newname for datafile 5 to '/data/temp/example01.dbf' ;
14> sql "alter database datafile ''/data2/vol1/users01.dbf'' offline drop" ;
15>
16> restore database skip tablespace 'users' ;
17> switch datafile all ;
19> sql 'alter session set nls_date_format="YYYY-MM-DD:HH24:MI:SS"' ;
20> set until time='2013-02-19:10:38:23' ;
22> recover database skip tablespace 'users' ;
23> alter database open resetlogs ;
24> }
4) Drop tablespace 복구하기
RMAN> run {
2> shutdown immediate ;
3> startup nomount ;
4> sql 'alter session set nls_date_format="YYYY-MM-DD:HH24:MI:SS"' ;
5> restore controlfile from '/data2/backup/rman/02o2bu90_1_1_20130219' ;
6>
7> alter database mount ;
8> sql 'alter session set nls_date_format="YYYY-MM-DD:HH24:MI:SS"' ;
9> set until time='2013-02-19:11:31:42' ;
10>
11> restore database ;
12> recover database ;
13> }
https://hayleyfish.tistory.com/107
https://dinggur.tistory.com/144
https://hayleyfish.tistory.com/109
http://www.gurubee.net/lecture/1983
'Oracle > backup' 카테고리의 다른 글
아카이브 모드에서 완전복구/불완전복구 (0) | 2022.01.26 |
---|---|
Cold Backup && Hot Backup (0) | 2022.01.26 |
RMAN (Recovery Manager) (0) | 2022.01.26 |
BCT(Block change tracking) (0) | 2022.01.26 |