Linux 에서 Oracle 데이터베이스 백업

먼저 스 크 립 트 를 사용 하지 않 고 명령 백업 과 Oacle 데이터 베 이 스 를 복원 하 는 Oracle 데이터 백업 을 소개 합 니 다.단계 1 사용자 데 이 터 를 백업 합 니 다.1.Liux 시스템 의 데이터베이스 관리자 계 정 을 사용 하여 Liux 단말 기 를 연결 합 니 다.2.다음 문 구 를 실행 하여"bak"을 만 듭 니 다.dir 폴 더.

 mkdir bak_dir
 
3.다음 문장 을 집행 하면'bakdir 폴 더 는 읽 기,쓰기,실행 권한 을 부여 합 니 다.

 chmod 777 bak_dir
 
4.다음 문 구 를 실행 하고 sysdba 사용자 로 Oacle 데이터베이스 서버 에 로그 인 합 니 다. sqlplus 데이터베이스 관리자 계 정/비밀번호@데이터베이스 인 스 턴 스 이름 as sysdba 5.다음 문 구 를 실행 하면"bak"dir"지정"/opt/oracle/bakdir”。

 create or replace directory bak_dir as '/opt/oracle/bak_dir'
 commit
 
6.다음 문장 을 실행 하고"bakdir'의 읽 기,쓰기,실행 권한 은 xx(데이터 사용자 이름)사용자 에 게 부여 합 니 다.
 
 grant all on directory bak_dir to xx
 commit
 
7.다음 문 구 를 실행 하고 Oacle 데이터베이스 서버 를 종료 합 니 다.

quit
다음 문 구 를 실행 하고 sysdb 사용자 의 시 계 를"bak"로 백업 합 니 다.dir 디 렉 터 리 아래.8.

expdp xx( )/xx( )@ directory=bak_dir dumpfile=expdb_xx.dmp logfile=expdb_xxlog tables=
 Oracle 데이터 복원:1.명령 행 에 입력:

sqlplus "/as sysdba"
2.다음 문 구 를 실행 하여 xx 데이터베이스 에 로그 인 합 니 다.사용자 이름:xx,비밀번호:xx(현지 실제 암 호 를 입력 하 십시오) conn xx/xx;3.복 구 된 표 에 트리거 와 관련 된 것 이 있 으 면 트리거 를 중단 하 십시오.예:A 표

alter table A disable all triggers;
commit;
 
4.다음 문 구 를 실행 하여 현재 사용 자 를 종료 하 십시오. quit;5.다음 문 구 를 실행 하여 사용자 데 이 터 를 복원 합 니 다.

 impdp xx/xx@ directory=bak_dir table_exists_action=truncate dumpfile=expdb_xx.dmp logfile=impdb_xx.log
5.명령 행 에 입력:sqlplus"/as sysdba"6.다음 문 구 를 실행 하여 xx 데이터베이스 에 로그 인 합 니 다.사용자 이름:xx,비밀번호:xx(현지 실제 암 호 를 입력 하 십시오) conn xx/xx;7.다음 문 구 를 실행 하여 금 지 된 트리거

alter table A enable all triggers;
commit;
 
을 여 는 방법 은 우리 가 원 하 는 것 을 실현 할 수 있 지만 대형 WEB 서버 는 자동 으로 정시 에 백업 해 야 합 니 다.

1.--
2.create tablespace test_data
3.logging
4.datafile '/u01/app/oradata/test/TEST.dbf'
5.size 32m
6.autoextend on
7.next 32m maxsize 2048m
8.extent management local;
9.
10.--
11.create user TEST identified by 123
12.default tablespace test_data
13.temporary tablespace temp;
14.
15.--
16.grant connect,resource to TEST;
 
은 Test 사용자 로 로그 인하 여 시 계 를 만 들 고 두 개의 데 이 터 를 삽입 합 니 다.

create table t1(
Id varchar(50) primary key,
title varchar(50)
);
insert into t1 values(sys_guid(),'t1');
insert into t1 values(sys_guid(),'t2');
commit;
은 내 보 낸 스 크 립 트 파일 을 먼저 작성 합 니 다.

export ORACLE_BASE=/u01/app
export ORACLE_HOME=/u01/app/oracle
export ORACLE_SID=TEST
export PATH=$ORACLE_HOME/bin:$PATH
d=$(date '+%Y%m%d')
exp TEST/123@TEST file=/home/oracle/backup/$d.dmp log=/home/oracle/backup/$d.log owner=TEST
zip -m /home/oracle/backup/$d.zip /home/oracle/backup/$d.dmp /home/oracle/backup/$d.log
 
앞의 4 문장 은 환경 변 수 를 설정 합 니 다.crontab 가 정시 에 호출 할 때 Oacle 사용자 의 환경 변 수 를 사용 하지 않 기 때문에 먼저 이 를 유도 해 야 합 니 다.여섯 번 째 줄 은 현재 날짜 로 내 보 낸 파일 이름 입 니 다.예 를 들 어 20120626.dmp 와 20120626.log 입 니 다.일곱 번 째 줄 은 이 두 파일 을 하나의 zip 패키지 로 만 들 고 이 두 파일 을 삭제 합 니 다.chmod 명령 으로 이 sh 를 실행 가능 한 것 으로 표시 하려 면

chmod +x backup.sh
 
Oacle 사용자 로 crontab-e 명령 을 입력 하고 Oacle 사용자 의 작업 계획 을 편집 하 십시오. 코드 는 다음 과 같 습 니 다.1.[oracle@localhostbackup]$crontab-e 2.42 13***/home/oracle/backup/backup.sh 이렇게 계획 을 추가 하여 매일 13 시 42 분 에/home/oracle/backup/backup.sh 를 실행 합 니 다.이렇게 하면 됩 니 다.Liux 계획 임 무 를 이용 하여 이 루어 집 니 다.백업 정책:일요일 0 급 월요일,화요일,목요일,금요일,토요일 2 급 수요일 1 급

--
mkdir -p /dinglp/ora_managed/backup
mkdir -p /dinglp/ora_managed/backup
mkdir -p /dinglp/ora_managed/backup/export-

mkdir -p /dinglp/ora_managed/backup/log
mkdir -p /dinglp/ora_managed/backup/rman_backup
mkdir -p /dinglp/ora_managed/scripts
-- rman rman
create tablespace rman_tbs datafile '/oradata/luke/rman_tbs01.dbf' size 1024M;
create user rman_dlp identified by dlp default tablespace rman_tbs temporary tablespace temp;
grant connect,resource ,recovery_catalog_owner to rman;
-- catalog
rman catalog rman_dlp/dlp
create catalog tablespace rman_tbs;
connect target sys/dg@priamry
register database;
report schema;
--
configure retention policy to redundancy 2;
configure retention policy to recovery window of 7 days;
-- ( vi )
dlp-> touch exp_rman.par
dlp-> touch exp_rman.sh
dlp-> touch rman_bk_LEVEL0.rcv   ( 0 )
dlp-> touch rman_bk_LEVEL0.sh
dlp-> touch rman_bk_LEVEL1.rcv ( 1 )
dlp-> touch rman_bk_LEVEL1.sh
dlp-> touch rman_bk_LEVEL2.rcv   ( 2 www.linuxidc.com)
dlp-> touch rman_bk_LEVEL2.sh
-- RMAN exp_rman.par
##################################################
###               exp_rman.par                 ###
##################################################
userid=rman_dlp/dlp
file=/dinglp/ora_managed/backup/export/rman.dmp
log=/dinglp/ora_managed/backup/log/rman.log
-- RMAN SHELL exp_rman.sh
##################################################
###                 exp_rman.sh                ###
##################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
exp parfile=exp_rman.par
-- RMAN rman_bk_LEVEL0.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format '/dinglp/ora_managed/backup/rman_backup/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d2;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
-- SHELL rman_bk_LEVEL0.sh
#####################################################################
###                   rman_bk_LEVEL0.sh                           ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL0.rcv msglog=$HOME/backup/log/rman_bk_LEVEL0.log
./dinglp/ora_managed/script/exp_rman.sh
-- RMAN rman_bk_LEVEL1.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
backup incremental level 1 format '/dinglp/ora_managed/backup/rman_backup/level1_%d_%s_%p_%u.bak' tag = 'level 1' database;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
-- SHELL rman_bk_LEVEL1.sh
#####################################################################
###                   rman_bk_LEVEL1.sh                           ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL1.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL1.log
. /dinglp/ora_managed/scripts/exp_rman.sh
-- RMAN rman_bk_LEVEL2.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
backup incremental level 2 format '/dinglp/ora_managed/backup/rman_backup/level2_%d_%s_%p_%u.bak' tag = 'level 2' database;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
-- SHELL rman_bk_LEVEL2.sh
#####################################################################
###                   rman_bk_LEVEL2.sh                           ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL2.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL2.log
. /dinglp/ora_managed/scripts/exp_rman.sh
-- RMAN
alter database enable block change tracking using file '/u01/app/Oracle/admin/devdb/bdump/luke.log';
desc v$block_change_tracking;
--RMAN
V$ARCHIVED_LOG             、 。
V$BACKUP_CORRUPTION    。
V$COPY_CORRUPTION    。
V$BACKUP_DATAFILE    。 。    V$BACKUP_REDOLOG    。
V$BACKUP_SET     。
V$BACKUP_PIECE    。
--
SET COMMAND ID 。
V$PROCESS V$SESSION, RMAN 。
V$SESSION_LONGOPS, 。
--linux
crontab
1 1~59
2 1~23(0 )
3 1~31
4 1~12
5 0~6(0 )
6
[root@dlp ~]# vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
00 22 * * 0 root /dinglp/ora_managed/scripts/rman_bk_LEVEL0.sh
00 22 * * 3 root /dinglp/ora_managed/scripts/rman_bk_LEVEL1.sh
00 22 * * 1,2,4,5,6 root /dinglp/ora_managed/scripts/rman_bk_LEVEL2.sh
-- ,RYOHEI,2010-08-04。
 

좋은 웹페이지 즐겨찾기