출처: 서진수 강사님 oracle 취업 강좌, oracle백업 과 복구 교재. oracle concepts 문서
◎ 백업의 대상
□ 필수 : Datafile , Redo Log File , Control File
□ 선택 : Parameter file, Password file, sqlnet.ora, listener.ora ,tnsnames.ora
Parameter file : 기본 설정이기 때문에
Password file : sysdba 권한의 dkaghfmf wjwkdgksms 파일
※ 다른 user dba_user(딕셔너리)에저장이됨 → open이 되야 조회가능 (open안되면 접속 못함)
→ sysdba 권한은 일반 OS 파일에 저장하고 확인하도록 설정
sqlnet.ora :
instener.ora :
tnsnames.ora:
◎ 종류
※추가 디스크 생성하기 (백업 전에 수행)
[DISK 생성하기]
fdisk -l
fdisk /dev/sdb
mkfs.ext3 /dev/sdb1
폴더 만든다음
chown -R oracle.oinstall /data
mount /deb/sdc1 /data/backup/close
mount /deb/sdc1 /data/backup/open
vi /etc/fstab
□ 닫힌 백업(clod backup/ closed backup)
특징 : DB를 종료후에 전부 복사해버리 면 끝
순서
① 정상종료
② os 상에서 db 백업
③ 다시 켜기
[oracle@server113 data]$ cp /app/oracle/oradata/testdb/control01.ctl /data/backup/close/
[oracle@server113 data]$ cp /app/oracle/flash_recovery_area/testdb/control02.ctl /data/backup/close/
[oracle@server113 close]$ cp /app/oracle/oradata/testdb/redo0* ./
[oracle@server113 close]$ cp /app/oracle/oradata/testdb/*.dbf ./
[oracle@server113 close]$ cp /app/oracle/product/11g/dbs/*.ora ./
[oracle@server113 close]$ cp /app/oracle/product/11g/dbs/orapwtestdb ./
[oracle@server113 admin]$ cd /app/oracle/product/11g/network/admin/* /data/backup/close/
□ 열린 백업(Hot backup/ Open backup/ Begin backup/Online Backup)
① 상황 DB가 OPEN 상태에서 Backup 받아야 하는경우
② 특징
백업모드 tablspace 단위로 작업 → 다른 사용자가 여전히 DML 사용가능
→ 모든 작업의 block을redo buffer에 저장 → redo log file 량이 많이 증가됨
→ archive log file 의 용량이 증가됨
※ OFFLINE과의 차이점: OFFLINE DB작업을 못하지만 backup은 DB 작업 가능
※ 반드시 archive 모드에서 실행 할것 ★
※ Online Redo Log File은 백업 받지 못함 (변경되는 데이터를 전부 쌓아 놓기 때문)
[Split Block]
Row 단위가 아니라 block 단위로 가져오는 이유는 oracle Block는 OS Block로 이루어져 있기 때문에
OS block 의 SCN도 항상 동일 해야함 → 해당 블록 전체를 저장
③ 실행 원리 ★
① Begin 명령으로 Cehck Point 생성해서 모든 Commit 된 데이터를 Data File에 저장
② 작업 완료의 Check Point SCN 정보를 Control File, Data File Header 에 저장
-- 중간에 들어오는 다른 DML, DDL 등의 작업은 Block 단위로 Redo Log Buffer에
기록되서 Redo log File에 저장
③ 해당 Table Space에 대한 복사 작업 수행
④ End Backup 명령으로 다시 Check Point를 발생 시켜서 Redo Log File 있는 SCN의 내용을
DataFile, Control File 에 적용
※ 해당 Table Space의 OffLine 작업 안됨 (Data File에 대한 접근은 막아 놓았기 때문)

④ 순서
① arichive 모드 확인
② 특정 Tablespace를 백업 모드 BEGIN
③ OS 에서 File 복사하기
④ 특정 Tablespace를 백업 모드 END
※ 보통 sh 로 많이 사용
[OPEN BACK 하는법]
alter tablespace users begin backup;
cp 해주어야함
alter tablespace users end backup;
[end active 조회하기]
set line 200
col name for a50
col status for a15
select a.file#, a.name, b.status , to_char(b.time,
'YYYY-MM-DD:HH24:MI:SS') as time
from v$datafile a, v$backup b
where a.file#=b.file#;
/
[쉘 스크립트] : 일자별로 백업 디렉터리를 생성 begin backup을 자동 수행
[main_backup] :begin_backup.sh, copy_backup,nd_backup.sh 차례로 실행
export LANG=C
export ORACLE_BASE=/home/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10g
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=testdb
echo ""
echo ""
echo "set begin backup mode~~"
time sh /home/oracle/begin_backup.sh >> /home/oracle/total.log
echo ""
echo "end begin backup mode~~"
echo ""
echo "start file copy....................."
time sh /home/oracle/copy_backup.sh >> /home/oracle/total.log
echo "end file copy~"
echo ""
echo "set end backup mode~~"
time sh /home/oracle/end_backup.sh >> /home/oracle/total.log
echo "complete hot backup~!"
[begin_backup.sh] : backup 모드로 변환하는 스크립트
set head off
set feedback off
set time off
set timing off
set echo off
spool /tmp/online.tmp
select 'alter tablespace '|| tablespace_name ||' begin backup;' \
from dba_tablespaces \
where status='ONLINE' \
and contents != 'TEMPORARY';
spool off
!cat /tmp/online.tmp | egrep -v spool | egrep -v SQL |egrep -v SYS| egrep -v [2-4] > /home/oracle/begin.sh
@/home/oracle/begin.sh
!sh /home/oracle/status.sh
exit
EOF1
[copy_backup] :OS 상에서 복사하는 스크립트
export LANG=C
export ORACLE_BASE=/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11g
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=testdb
sqlplus /nolog << EOF3
conn / as sysdba
set head off
set time off
set timing off
set feedback off
set echo off
set line 200
col name for a100
spool /app/oracle/cp.tmp
select 'mkdir /data/backup/open/'||to_char(sysdate,'YYYY-MM-DD-HH24-MI-SS') from dual;
select 'cp -av '||name||' /data/backup/open/'||to_char(sysdate,'YYYY-MM-DD-HH24-MI-SS') "name" from v\$datafile;
spool off
spool /app/oracle/control.tmp
alter session set nls_date_format='YYYY-MM-DD-HH24-MI-SS';
select 'alter database backup controlfile to ''/data/backup/open/'||sysdate||\
'/'||sysdate||'.ctl'';' from dual;
spool off
!cat /app/oracle/cp.tmp | egrep -v SQL |egrep -v SYS > /app/oracle/cp.sh
!cat /app/oracle/control.tmp | egrep -v SQL > | egrep -v SYS >/app/oracle/control.sql
!sh /app/oracle/cp.sh
@/app/oracle/control.sql
exit
EOF3
[end_backup.sh] : 복사 완료된것을 다시 end 시킨후 begin backup 볼수 있는 status.sh 실행
export LANG=C
export ORACLE_BASE=/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11g
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=testdb
sqlplus /nolog <<EOF1
conn / as sysdba
set head off
set feedback off
set time off
set timing off
set echo off
spool /app/oracle/end.tmp
select 'alter tablespace '|| tablespace_name ||' end backup;' \
from dba_tablespaces \
where status='ONLINE' \
and contents != 'TEMPORARY';
spool off
!cat /app/oracle/end.tmp | egrep -v spool | egrep -v SQL |egrep -v SYS | egrep -v [2-4] > /app/oracle/end.sh
@/app/oracle/end.sh
!sh /app/oracle/status.sh
exit
EOF1
[status.sh] : 상태를 조회하는 스크립트
export LANG=C
export ORACLE_BASE=/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11g
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=testdb
sqlplus /nolog <<EOF2
conn / as sysdba
set head on
set echo off
set feedback off
spool /app/oracle/status.tmp
set line 200
col name for a50
col status for a15
select a.file#,a.name,b.status,to_char(b.time,'YYYY-MM-DD:HH24:Mi;SS') "Time" \
from v\$datafile a ,v\$backup b \
where a.file#=b.file#;
spool off
exit
EOF2
□ 기타 사항 (Passward File 관리)
① netca 한다음 sqlnet.ora 생성
② [oracle@server113 dbs]$ cd /app/oracle/product/11g/dbs/
③ [oracle@server113 dbs]$rm orapwtestdb
④ [oracle@server113 dbs]$ orapwd file=/app/oracle/product/11g/dbs/orapwtestdb
⑤ 새로운 비밀 번호 설정
※ DB 를 새로 설치하면 반드시 SYS 계정의 암호를 설정해 줄것