NT 의 OCOPY 를 이용한 HOT BACKUP SCRIPT
제품 : ORACLE SERVER
작성날짜 : 2002-04-25
NT 의 OCOPY 를 이용한 HOT BACKUP SCRIPT
========================================
PURPOSE
다음은 NT에서 OCOPY를 이용하여 HOT BACKUP을 하는 SCRIPT를
제공한다.
Examples
1) <Batch file 1 >
Online_backup_data 라는 batch file 은 다음처럼 이루어질 수 있다.
svrmgr23 @d:\temp\begin_user_backup.sql
ocopy73 d:\orant\database\usr1orcl.ora d:\temp\usr1orcl.bck
svrmgr23 @d:\temp\end_user_backup.sql
svrmgr23 @d:\temp\begin_SYS_backup.sql
ocopy73 d:\orant\database\SYS1orcl.ora d:\temp\SYS1orcl.bck
svrmgr23 @d:\temp\end_SYS_backup.sql
svrmgr23 @d:\temp\begin_temp_backup.sql
ocopy73 d:\orant\database\TMP1orcl.ora d:\temp\TMP1orcl.bck
svrmgr23 @d:\temp\end_temp_backup.sql
로 만들 수 있다.
이 때 begin_user_backup.sql file 내용은
connect system/manager
alter tablespace user_data begin backup;
exit; 이고 ,
또 end_user_backup.sql file 내용은
connect system/manager
alter tablespace user_data end backup;
exit;
로 구성되어야 한다.
2) 또는 BATCH FILE 을 다음처럼 구성할 수 있다.
svrmgr23 @d:\temp\backup.sql
backup.sql script 내용은 다음과 같이 작성한다.
connect system/manager
alter tablespace user_data begin backup;
host ocopy73 e:\orant\database\usr1orcl.ora d:\tmp\usr1orcl.bck
alter tablespace user_data end backup;
alter tablespace SYSTEM begin backup;
host ocopy73 e:\orant\database\SYS1orcl.ora d:\tmp\SYS1orcl.bck
alter tablespace SYSTEM end backup;
alter tablespace ROLLBACK_DATA begin backup;
host ocopy73 e:\orant\database\RBS1orcl.ora d:\tmp\RBS1orcl.bck
alter tablespace ROLLBACK_DATA end backup;
alter tablespace TEMPORARY_DATA begin backup;
host ocopy73 e:\orant\database\TMP1orcl.ora d:\tmp\TMP1orcl.bck
alter tablespace TEMPORARY_DATA end backup;
exit;
Reference Documents
--------------------
Similar Messages
-
Oracle Hot Backup Script Windows Server 2003
Hello,
Does anyone here have a working Oracle 10I database hot backup script for Windows Server 2003? If so can you please post it here.
Thanks.Here is a basic batch script I have used for a hot backup of Oracle databases using RMAN
Will just need to update some locations based on you environment just check all the comments and change what you need to but this can be scheduled to run regularly through the windows scheduler for database backups.
This will take a hot backup and backup the archive logs.
Let me know if you have any quesitons.
REM #####################################################################
REM # Name: rman_hot_backup_dsk.bat
REM #
REM # Description:
REM #
REM # Generic Hot backup script that accepts the SID
REM #
REM # Parameters: Instance Name, backup level
REM #
REM #####################################################################
REM #
REM # Check if SID was Passed
if (%1)==() goto USAGE
if (%2)==() goto USAGE
REM # assign ORACLE_SID to passed SID
set ORACLE_SID=%1
REM # Set the hot backup level 0-full 1-incremental
set LEVEL=%2
REM # export the page list
set [email protected]
REM # assign a date we can use as part of the logfile
set DTE=%date:~-4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%
REM # Take the spaces out of the date string so we can use in our file name
set DTE=%DTE: =%
REM # set the script location
REM # Set location of where you will put script
set SCRIPTLOC=C:\app\oracle\scripts
cd %SCRIPTLOC%
REM # Set the Temporary command file that we will write our rman script to
set CMDFILE=%SCRIPTLOC%\%ORACLE_SID%_rman_hot_backup_dsk.cmd
REM # Remove the temporary file if it exists
del /q %CMDFILE%
REM # Set the logfile directory
REM # Change based on where you want the backup logs to go
set LOGPATH=W:\ORACLE_BACKUP\logs
set LOGFILE=%ORACLE_SID%_rman_hot_backup_dsk_%DTE%.log
set LOG=%LOGPATH%\%LOGFILE%
REM # Set the path of the backup location
REM # Change based on disk pach for you disk based backups
set BACKLOC=\\VirtualBox\ORA_ITS03P\ORACLE_BACKUP\%ORACLE_SID%
REM # Lets set the ORACLE_HOME for the host
REM # Set to your actual ORACLE_HOME location
set ORACLE_HOME=C:\app\oracle\product\10.2.0\db_1
# Set the rest of the Oracle Environment
# based on our ORACLE_HOME
set LIBPATH=%ORACLE_HOME%/lib
set LD_LIBRARY_PATH=%ORACLE_HOME%/lib
set TNS_ADMIN=%ORACLE_HOME%/network/admin
REM #set ORA_NLS10=%ORACLE_HOME%/nls/data
REM Set our PATH with the ORACLE_HOME so that we have a good
REM clean environment to work with
set PATH=%ORACLE_HOME%/bin;%ORACLE_HOME%/OPatch;%PATH%
REM # Write Temporary command file for RMAN backup
echo # configure retention policy >> %CMDFILE%
echo CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # lets start clean for our hot backup by doing full crosschecks >> %CMDFILE%
echo change archivelog all crosscheck ; >> %CMDFILE%
echo crosscheck backup of database; >> %CMDFILE%
echo crosscheck backup of controlfile; >> %CMDFILE%
echo # >> %CMDFILE%
echo # delete all expired and obsolete backups >> %CMDFILE%
echo allocate channel for maintenance type disk ; >> %CMDFILE%
echo delete noprompt expired archivelog all ; >> %CMDFILE%
echo delete noprompt expired backup ; >> %CMDFILE%
echo delete noprompt obsolete ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Configure control file for auto backup >> %CMDFILE%
echo configure controlfile autobackup on ; >> %CMDFILE%
echo CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%BACKLOC%\%ORACLE_SID%_controlfile_%%F' ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Configure default device type here we use disk and set parallelism to 2 >> %CMDFILE%
echo configure default device type to disk ; >> %CMDFILE%
echo configure device type disk parallelism 2 ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Must format the default channel for the device type disk >> %CMDFILE%
echo # other wise tmp area in creating pieces will be done in >> %CMDFILE%
echo # the $ORACLE_HOME/dbs directory >> %CMDFILE%
echo CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT = '%BACKLOC%\%ORACLE_SID%_hot_%%U' ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Configure our retention policy for this database >> %CMDFILE%
echo configure retention policy to recovery window of 14 days ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Let configure our channels for our backup >> %CMDFILE%
echo # Channel 1 disk and we indicate where it goes not taking the default >> %CMDFILE%
echo configure channel 1 device type disk MAXPIECESIZE = 4G format '%BACKLOC%\%ORACLE_SID%_hot_%%U' ; >> %CMDFILE%
echo # Channel 2 disk and we indicate where it goes not taking the default >> %CMDFILE%
echo configure channel 2 device type disk MAXPIECESIZE = 4G format '%BACKLOC%\%ORACLE_SID%_hot_%%U' ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Backup our database with compression on >> %CMDFILE%
echo backup as compressed backupset incremental level %LEVEL% tag hot_%LEVEL%_%DTE% DATABASE ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Backup our archive log files that have not been backed up >> %CMDFILE%
echo backup as compressed backupset format '%BACKLOC%\%ORACLE_SID%_Archive_%%d_%%s_%%p_%%t' archivelog all not backed up 1 times ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Backup Control file for standby in case needed >> %CMDFILE%
echo backup current controlfile for standby ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # let put a controlfile to trace >> %CMDFILE%
echo sql 'ALTER DATABASE BACKUP CONTROLFILE TO TRACE' ; >> %CMDFILE%
REM # Run the RMAN backup without using the recovery catalog
%ORACLE_HOME%\bin\rman target=/ nocatalog cmdfile=%CMDFILE% msglog=%LOG%
REM # Remove our temporary command file
del /q %CMDFILE%
REM # Mail Archive backup log
REM # This relies on the free bmail utility
bmail -date -m %LOG% -f [email protected] -s <smtpserver> -t %PAGE_LIST% -a "HOT Backup results"
REM # Goto end of script as we are done
goto END
:USAGE
echo "Must Pass ORACLE_SID and hot backup level as parameters."
goto END
:END -
Win2000/NT hot backup script
Can someone provide a basci script for online(hot) backup for Oracle9i(8i) on Windows2000/NT server? we have a online application, and plan to back it up every night.
Also, Windows should have administrative tool to schedule the backup by envoking the script every night after we set it up, right?
Many THANKS for your help!!!Hope this solves ur problem
Run this script through SQLPLUS and it will ask you for the
HOT_BACK_DIR and GEN_FILE values.
HOT_BACK_DIR : defines the directory to which the hot backup is written
SCRIPT_FILE : Hot Backup Script for your environment
INT_PWD :Internal Password ( Needed for NT Only )
Give me the Credit and never use it without askin me ;)
****************************** DO NOT DELETE*********************/
define HOT_BACK_DIR = &1
define SCRIPT_FILE = &2
define INT_PWD = &3
/* Create Temporary Table with Tablespace Data */
drop table dsc_hot_stage;
create table dsc_hot_stage
tablespace_name varchar2(30),
file_name varchar2(200)
insert into dsc_hot_stage
select rtrim(tablespace_name),rtrim(file_name) from sys.dba_data_files;
/**** Set up the parameters for the spool file */
set feedback off
set heading off
set pagesize 0
set linesize 128
set verify off
set termout oN
set echo off
spool &SCRIPT_FILE
select '/* ',
'**** This is the hot backup script and has been generated',
'**** by gen_hot_dos.sql.',
'**** ' || to_char(sysdate, 'MM/DD/YYYY HH:MI:SS') ,
'**** You are Allowed to Use this script freely as long '
'**** as this title is not deleted
'**** For more Scripts Visit DBASUPPORT.COM */'
from dual;
select 'connect internal/&3' from dual;
-- Create Script to backup Control File to Trace
select 'alter database backup controlfile to trace; '
from dual;
-- Create Script to backup actual files to a directory
select 'alter tablespace '|| tablespace_name||' begin backup;' c1,
'host ocopy80 '||file_name||' &HOT_BACK_DIR' || '\' ||
substr(file_name,instr(rtrim(file_name),'\',-1,1)+1,length(rtrim(file_name)))||
'.bak' c2
from dsc_hot_stage
union
select 'alter tablespace '|| tablespace_name||' end backup;' c1,
null c2,
from dsc_hot_stage
group by tablespace_name,file_name order by 1;
select 'exit' from dual;
spool off -
Hot Backup을 Script로 작성후 Cron으로 실행시...
안녕하세요!
건강한 가을 보내시고 계신지요?
오늘은 Hot Backup에 대해서 몇가지 궁금한게 있어서 글을 올립니다
-. HP-UNIX 11, Oracle 9.2.0.7
-. Oracle Database 파일 용량 : 약 50G
-. Script 내용중 일부 발췌
alter system switch log file; <--백업해야할 dbf 양이 많아 먼저 한번 실행시켰음
####### Tablespace Backup
alter tablespace system begin backup;
!cp /oradata/system01.dbf /BACKUP/hot/system01.dbf
alter tablespace system end backup;
...........각 테이블스페이스별로 위와 같이 정의
####### Archive Log File Backup
alter system switch log file;
alter system archive log off;
!cp /oradata/arch/*.arc /BACKUP/hot/arch/.
!rm /oracle/arch/*.arc
alter system archive log start;
####### Control File Backup
alter system checkpoint;
alter database backup controlfile '/BACKUP/hot/control.bkp';
위와 같이 Script를 작성하여, Cron을 사용하여 야간에 작업을 수행코자 합니다.
1. 위의 Script에서 수정을 가해야 하는 부분이나, 좀 더 추가되어야할 부분이 있으시면 기탄없이 지적 부탁드립니다.
2. 야간에 작업을 수행하다보니, Tablespace의 Begin backup을 했는데, 여타의 장애로 인해 End Backup이 수행이 안될경우, DBA가 강제로 End Backup을 안해줄 경우에는 어떻게 되는지요?
그리고, 이러한 위험을 해결키 위해 고수님들은 어떠한 방법을 사용하는지 알고 싶습니다.
행복한 하루 되십시요!
감사합니다.첫번째로..
백업초기에 log switch를 하는 것은 경험상 필요하기도 합니다.
트랜잭션이 거의 없는 백업본의 경우에 archive가 거의 떨어지지
않게 되고, 하루 백업하는데 백업본에 archive는 없는 이상한 사태가
벌어지죠. 차후에 cancel복구를 해야 하는 경우에도 어렵기 때문에
online backup 시 초기에 log switch 를 해주기는 합니다.
두번째로..
alter system archive log stop; 명령은 왜 하셨는지요?
이거 하면.. archiveing 이 멈추니 트랜잭션도 멈춥니다. 서비스 영향을
줄텐데요.. 백업이 서비스에 영향을 주어서는 안되겠죠.
archive log를 백업시에는 파일명에 대한 리스트를 만들고 그 리스터에
있는 파일들을 백업후 삭제하는 방법으로 변경하시는 것이 좋을 것 같습니다.
세번째로.. 컨트롤파일 백업은 tablespace backup 이후에
바로 하시는 것이 좋습니다. archive file을 백업하는 시간동안
SCN이 변경이 되겠고, 그러면 해당 컨트롤파일을 백업하고 그것을
restore하게 되면 controlfile의 scn이 틀리니 controlfile의 SCN까지
복구가 필요하다고 판단하겠죠.
순서를.. 테이블스페이스 데이터파일 백업 -> 컨트롤파일 백업 -> 아카이브백업
이런 순으로 하시면 좋을 것 같습니다.
네번째로..
begin backup을 하게 되면 테이블스페이스의 데이터파일 헤더에는 bebin
backup mode라고 쓰게 됩니다. 그리고 이렇게 begin backup mode인
테이블스페이스에서 변경된 데이터는 그 데이터를 row 단위로 redo log entry에
등록하는 것이 아니라 블록단위로 등록하게 됩니다. 즉 단 하나의 row만을
update했을 뿐인데도 해당 block전체가 redo log entry로 들어가겠죠. 당연히
archive file이 훨씬 많이 쌓이게 됩니다. 또한 DB를 abort로 내렸을 경우에는
이후에 open을 하려고 하면 system01.dbf 파일을 복구하라고 나와서
아주 당황하게 되지요.
그리고 사례를 보면..모 시청에서 DBA가 한달동안
begin backup이 된 것을 몰랐고, DB fail이 났는데..복구를 한답시고
controlfile을 재생성하였습니다. 그런데 bootstrap failure가 발생했고
게다가 아카이브도 없고 백업도 없는 것이었습니다. 결국엔 adjust scn으로
강제복구를 했지요.. begin backup mode인지는 아침에 시스템담당자가
꼭 확인해야 하는 것 중에 하나입니다. 아침 점검 스크립트 수행하지
않으시는지요?
첨부로.. 얼마전에 여기 게시판에도 올렸던 내용인데요..
백업 스크립트를 드리죠..
그리고 아침에 DB를 점검할 때 보아야 하는 사항은 제가 정리한 것이
있습니다.
아래 링크에서 다운받아서 참고하세요.
http://www.dbguide.net/servlet/com.util.DownloadServlet?file=%2F20060120%2F1137768090586.zip&filename=%C0%CF%C0%CF+DB%C1%A1%B0%CB+%BD%BA%C5%A9%B8%B3%C6%AE_%B0%F8%B0%B3%BF%EBv0.1.zip
===================================================
온라인 백업은 파라메터 파일 , 콘트롤 파일, 모든 데이터파일 , 아카이브로그를
백업후 다른 서버로 이동시키면 다른 서버로 복구할 수 있습니다.
하지만 online backup시에 datafile, controlfile만을 백업하므로 current redo log가 없으므로
until cancel 복구를 해야 합니다.(rman 백업도 마찬가지)
1) init파일,DB file, controlfile을 다른서버로 이동시킵니다.
보통 controlfile백업은 alter database backup controlfile to '~~'; 이렇게 하기 때문에
하나만 복사하므로 이것을 추가 복사해서 controlfile의 경로에 복사해줍니다.
2) init파일에 controlfile의 경로, background_dump_dest, user_dump_dest, core_dump_dest, log_archive_dest 를
경로에 맞게 지정해줍니다.
3) DB를 mount상태로 올립니다. 만약 mount하는 동안 에러가 난다면 controlfile에서
문제가 생겼으므로 controlfile의 백업을 확인합니다.
4) datafile, redolog file의 file_name을 변경합니다.
select name from v$datafile;
select member from v$logfile;
alter database rename file '현재경로' to '이동시킨 경로';
alter database rename file '현재경로' to '이동시킨 경로';
단 여기에서 tempfile은 백업대상도 아니고 rename이 안되므로 새로 생성해 주어야 합니다.
select name from v$tempfile;
select * from sys.props$;에서 default temporary tablespace를 찾거나
또는 select distiinct temporary_tablespace from dba_users 에서 찾습니다.
tempfile을 추가하는 방법은 더이상 말씀 안드립니다. NBR과정의 기본이니까요..
5) DB의 archive file을 log_archive_dest 에 설정된 곳으로 이동시키고 recovery를 수행합니다.
recover database until cancel;
마지막 archvie까지 적용후 cancel하기
alter database open resetlogs;
resetlogs open하기
# 온라인 백업 스크립트(데이터파일, 컨트롤파일만 백업)
작업 이전에 /backup , /backup/control 이라는 디렉토리 생성
- 백업 메인
vi /backup/onbackup.sh
export LANG=C
export ORACLE_HOME=/u/ora9i/product/9.2.0
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=PROD
sh -x /backup/1_onbackup.sh
sh -x /backup/2_cp_backup.sh
sh -x /backup/3_control_backup.sh
sh -x /backup/4_offbackup.sh
- 백업 모드 변경
vi /backup/1_onbackup.sh
export LANG=C
export ORACLE_HOME=/u/ora9i/product/9.2.0
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=PROD
# backup mode on
sqlplus /nolog << EOF1
conn /as sysdba
set head off
set feedback off
set time off
set timing off
set echo off
spool /tmp/backup_online.tmp
select 'alter tablespace '||tablespace_name||' begin backup;' from dba_tablespaces where status='ONLINE' and contents <>'TEMPORARY';
spool off
!cat /tmp/backup_online.tmp|grep -v spool|grep -v SQL > /tmp/backup_online.sql
@/tmp/backup_online.sql
exit
EOF1
- 데이터파일 백업할 쿼리
vi /backup/2_cp_backup.sql
select 'mkdir /backup/'||to_char(sysdate,'YYYYMMDD_HH24MI') from dual;
select 'cp '||name||' /backup/'||to_char(sysdate,'YYYYMMDD_HH24MI') from v$datafile;
- 데이터파일 copy하는 스크립트
vi /backup/2_cp_backup.sh
# cp backup, mkdir /backup/SYSDATE directory
export LANG=C
export ORACLE_HOME=/u/ora9i/product/9.2.0
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=PROD
sqlplus /nolog << EOF2
conn /as sysdba
set head off
set feedback off
set time off
set timing off
set echo off
spool /tmp/backup_script.tmp
@2_cp_backup.sql
spool off
!cat /tmp/backup_script.tmp |grep -v spool |grep -v SQL > /tmp/backup_script.sh
!chmod 755 /tmp/backup_script.sh
exit
EOF2
sh -x /tmp/backup_script.sh
- 컨트롤파일 백업
vi /backup/3_control_backup.sh
export LANG=C
export ORACLE_HOME=/u/ora9i/product/9.2.0
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=PROD
# controlfile backup
sqlplus /nolog << EOF3
conn /as sysdba
set head off
set feedback off
set time off
set timing off
set echo off
spool /tmp/control_backup.tmp
select 'alter database backup controlfile to ''/backup/control/'||to_char(sysdate,'YYYYMMDD_HH24MI')||'.ctl'';' from dual;
spool off
!cat /tmp/control_backup.tmp |grep -v spool|grep -v SQL > /tmp/control_backup.sql
@/tmp/control_backup.sql
exit
EOF3
- 백업모드 offline하기
vi /backup/4_offbackup.sh
export LANG=C
export ORACLE_HOME=/u/ora9i/product/9.2.0
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=PROD
# backup mode off
sqlplus /nolog << EOF4
conn /as sysdba
set head off
set feedback off
set time off
set timing off
set echo off
spool /tmp/backup_offline.spool
select 'alter tablespace '||tablespace_name||' end backup;' from dba_tablespaces where status='ONLINE' and contents <>'TEMPORARY';
spool off
!cat /tmp/backup_offline.spool |grep -v SQL > /tmp/backup_offline.sql
@/tmp/backup_offline.sql
exit
EOF4
그리고 만약 파일리스트만 내리고 veritas netbackup으로 백업이 가능하다면 아래와 같이 하면
됩니다. veritas netbackup에서는 file리스트만 파일로 떨구면 그 파일을 백업해줍니다.
archvie backup은 아래와 같이 하면 되는데 아래는 archive file의 backup list만 만듭니다.
수정해서 backup list에서 YYYYMMDD_HH24MI의 분단위 디렉토리를 만들고 archive file을
다른 서버로 cp복사하도록 하면 됩니다. 꼭 아래 스크립트는 테스트 후에 사용하시길
바랍니다...
# 데이터파일 백업과 archvie백업 쉘은 아래와 같습니다.
1. begin backup할 스크립트를 수행합니다.
dbbegin.sh
TBS_INFO=/tmp/tbs_info~.$$
sqlplus /nolog << EOF > $TBS_INFO 2>&1
connect / as sysdba;
select 'tablespace '||tablespace_name from dba_tablespaces;
disconnect;
exit
EOF
cat $TBS_INFO | awk ''$1 == "tablespace" { print $2 }'' | while read LINE
do
export LINE
echo "Issuing alter tablespace $LINE begin backup;"
/usr/openv/netbackup/oracle/table_begin.sh
done
\rm $TBS_INFO
2. 위에서의 table_begin.sh 는 아래와 같습니다.
table_begin.sh
sqlplus /nolog << EOF > /dev/null 2>&1
connect / as sysdba;
alter tablespace $LINE begin backup;
disconnect;
exit
EOF
3. dbbegin.sh 을 하게 되면 테이블스페이스가 backup mode가 됩니다.
4. 데이터파일 리스트를 추출합니다.
datafile_list
#!/bin/ksh
DATAFILE_INFO=/tmp/datafile_info~.$$
datafile_list=/tmp/PROD_data_list
sqlplus /nolog << EOF > $DATAFILE_INFO 2>&1
connect / as sysdba;
select ''datafile_name ''||file_name from dba_data_files;
select ''logfile_name ''||member from v\$logfile;
select ''controlfile_name ''||name from v\$controlfile;
disconnect
EOF
cat $DATAFILE_INFO | awk ''$1 == "datafile_name" {print $2}''
/tmp/PROD_dbfile_list cat $DATAFILE_INFO | awk ''$1 == "logfile_name" {print $2}''
/tmp/PROD_logfile_list cat $DATAFILE_INFO | awk ''$1 == "controlfile_name" {print $2}''
/tmp/PROD_controlfile_list cat /tmp/PROD_dbfile_list > $datafile_list
cat /tmp/PROD_logfile_list >> $datafile_list
cat /tmp/PROD_controlfile_list >> $datafile_list
\rm $DATAFILE_INFO
5. 데이터파일 리스트를 netbackup에서 tape백업을 하도록 합니다.
veritas netbackup에서 리스트만 주면 백업해줌..
6. end backup 을 만드는 스크립트를 수행
dbend.sh
#!/bin/ksh
TBS_INFO=/tmp/tbs_info~.$$
sqlplus /nolog << EOF > $TBS_INFO 2>&1
connect / as sysdba;
select ''tablespace ''||tablespace_name from dba_tablespaces;
disconnect;
exit
EOF
cat $TBS_INFO |awk ''$1 == "tablespace" { print $2 }''|while read LINE
do
export LINE
echo "Issuing alter tablespace $LINE end backup;"
/usr/openv/netbackup/oracle/table_end.sh
done
\rm $TBS_INFO
7. 위에서 table_end.sh 는 아래와 같습니다.
table_end.sh
sqlplus /nolog << EOF > /dev/null 2>&1
connect / as sysdba;
alter tablespace $LINE end backup;
disconnect;
exit
EOF
6. archive log가 없을 수 있으므로 수동으로 log switch 해줍니다.
arch_list_1
#!/bin/ksh
sqlplus /nolog << EOF > $LOG
connect / as sysdba;
alter system switch logfile;
disconnect;
exit;
EOF
7. archvie file의 리스트를 뽑아냅니다.
arch_list
#!/bin/ksh
TBS_INFO=/tmp/tbs_info~.$$
ARCHIVE_DIR=/tmp/PROD_archive_dir.txt
sqlplus /nolog << EOF > $LOG 2>&1
connect / as sysdba;
alter system switch logfile;
disconnect;
exit;
EOF
sqlplus /nolog << EOF > $TBS_INFO 2>&1
connect / as sysdba;
archive log list;
disconnect;
exit;
EOF
cat $TBS_INFO | awk ''$1 == "Archive" {print $3}'' > $ARCHIVE_DIR
ARCH_DIR=
cat $ARCHIVE_DIR
ARCH_LIST_PROD=
ls -ltr $ARCH_DIR/*.arc |wc -l
echo "ARCH_LIST_PROD : $ARCH_LIST_PROD" >> $LOG
ARCH_LIST_PROD_1=
expr$ARCH_LIST_PROD - 1
echo "ARCH_LIST_PROD_1 : $ARCH_LIST_PROD_1" >> $LOG
/usr/bin/ls -ltr $ARCH_DIR/*.arc |awk ''{print $9}'' |head -
$ARCH_LIST_PROD_1 > /tmp/PROD_arch_list
echo "Archive Log List Print.....O.k....
/usr/bin/date +%c
" >> $LOG
#\rm $TBS_INFO $ARCHIVE_DIR
8. 위에서 /tmp/PROD_arch_list에 있는 archive리스트를 veritas netbackup에서 넣어주면 tape백업이 됩니다.그리고 특이한 것은 archvie file은 archive file을 백업했으면
지우도록 설정하면 되겠지요. -
Rman hot backup script gives error in R12.
hi experts
i m facing following prob when run the backup script. 1 day before the same script runs correctily but now it gives me error at the allocatioion of channel rest of command run correctly.
[root@testerp rman_log]# cat UAT_daily_rman_hot_bkp_01-11-14_140301.log
-bash: /root/.bash_profile: Permission denied
Recovery Manager: Release 11.1.0.7.0 - Production on Sat Jan 11 14:03:01 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: UAT (DBID=2855851979)
connected to recovery catalog database
RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "end-of-file": expecting one of: "allocate, alter, advise, backup, beginline, blockrecover, catalog, change, copy, convert, crosscheck, configure, duplicate, debug, delete, execute, endinline, flashback, host, mount, open, plsql, recover, release, replicate, report, restore, resync, repair, }, set, setlimit, sql, switch, startup, shutdown, send, show, transport, validate"
RMAN-01007: at line 12 column 1 file: standard input
RMAN>
RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "for"
RMAN-01008: the bad identifier was: c2
RMAN-01007: at line 1 column 18 file: standard input
RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "for"
RMAN-01008: the bad identifier was: c3
RMAN-01007: at line 1 column 18 file: standard input
RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "for"
RMAN-01008: the bad identifier was: c4
RMAN-01007: at line 1 column 18 file: standard input
RMAN>
Starting backup at 11-JAN-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=362 device type=DISK
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00021 name=/d06/UAT/proddata/a_txn_data06.dbf
input datafile file number=00392 name=/d06/UAT/db/apps_st/data/a_txn_data01.dbf
input datafile file number=00401 name=/d06/UAT/db/apps_st/data/a_txn_data02.dbf
input datafile file number=00402 name=/d06/UAT/db/apps_st/data/a_txn_data03.dbf
input datafile file number=00022 name=/d06/UAT/proddata/a_txn_data07.dbf
input datafile file number=00014 name=/d06/UAT/db/apps_st/data/a_txn_data04.dbf
input datafile file number=00020 name=/d06/UAT/proddata/a_txn_data05.dbf
input datafile file number=00011 name=/d06/UAT/db/apps_st/data/sysaux01.dbf
input datafile file number=00018 name=/d06/UAT/db/apps_st/data/sysaux02.dbf
input datafile file number=00023 name=/d06/UAT/proddata/a_txn_data08.dbf
input datafile file number=00379 name=/d06/UAT/db/apps_st/data/undo01.dbf
input datafile file number=00024 name=/d06/UAT/proddata/sysaux03.dbf
input datafile file number=00025 name=/d06/UAT/proddata/sysaux04.dbf
input datafile file number=00033 name=/d06/UAT/proddata/a_txn_ind11.dbf
input datafile file number=00029 name=/d06/UAT/proddata/a_txn_ind09.dbf
input datafile file number=00030 name=/d06/UAT/proddata/a_txn_ind10.dbf
input datafile file number=00015 name=/d06/UAT/db/apps_st/data/a_txn_ind06.dbf
input datafile file number=00026 name=/d06/UAT/db/apps_st/data/a_txn_ind07.dbf
input datafile file number=00028 name=/d06/UAT/db/apps_st/data/a_txn_ind08.dbf
input datafile file number=00393 name=/d06/UAT/db/apps_st/data/a_txn_ind01.dbf
input datafile file number=00403 name=/d06/UAT/db/apps_st/data/a_txn_ind02.dbf
input datafile file number=00404 name=/d06/UAT/db/apps_st/data/a_txn_ind03.dbf
input datafile file number=00405 name=/d06/UAT/db/apps_st/data/a_txn_ind04.dbf
input datafile file number=00406 name=/d06/UAT/db/apps_st/data/a_txn_ind05.dbf
input datafile file number=00400 name=/d06/UAT/db/apps_st/data/a_media01.dbf
input datafile file number=00353 name=/d06/UAT/db/apps_st/data/system08.dbf
input datafile file number=00013 name=/d06/UAT/db/apps_st/data/system12.dbf
input datafile file number=00352 name=/d06/UAT/db/apps_st/data/system09.dbf
input datafile file number=00394 name=/d06/UAT/db/apps_st/data/a_ref01.dbf
input datafile file number=00407 name=/d06/UAT/db/apps_st/data/a_ref02.dbf
input datafile file number=00396 name=/d06/UAT/db/apps_st/data/a_summ01.dbf
input datafile file number=00395 name=/d06/UAT/db/apps_st/data/a_int01.dbf
input datafile file number=00008 name=/d06/UAT/db/apps_st/data/a_queue02.dbf
input datafile file number=00027 name=/d06/UAT/db/apps_st/data/a_queue03.dbf
input datafile file number=00031 name=/d06/UAT/db/apps_st/data/a_queue04.dbf
input datafile file number=00399 name=/d06/UAT/db/apps_st/data/a_queue01.dbf
input datafile file number=00001 name=/d06/UAT/db/apps_st/data/system01.dbf
input datafile file number=00002 name=/d06/UAT/db/apps_st/data/system02.dbf
input datafile file number=00003 name=/d06/UAT/db/apps_st/data/system03.dbf
input datafile file number=00004 name=/d06/UAT/db/apps_st/data/system04.dbf
input datafile file number=00005 name=/d06/UAT/db/apps_st/data/system05.dbf
input datafile file number=00398 name=/d06/UAT/db/apps_st/data/a_archive01.dbf
input datafile file number=00295 name=/d06/UAT/db/apps_st/data/system06.dbf
input datafile file number=00351 name=/d06/UAT/db/apps_st/data/system07.dbf
input datafile file number=00354 name=/d06/UAT/db/apps_st/data/system11.dbf
input datafile file number=00288 name=/d06/UAT/db/apps_st/data/system10.dbf
input datafile file number=00012 name=/d06/UAT/db/apps_st/data/apps_ts_tools01.dbf
input datafile file number=00016 name=/d06/UAT/db/apps_st/data/a_ref03.dbf
input datafile file number=00019 name=/d06/UAT/db/apps_st/data/MLSEIGL01.dbf
input datafile file number=00032 name=/d06/UAT/db/apps_st/data/RMAN01.dbf
input datafile file number=00397 name=/d06/UAT/db/apps_st/data/a_nolog01.dbf
input datafile file number=00314 name=/d06/UAT/db/apps_st/data/portal01.dbf
input datafile file number=00017 name=/d06/UAT/db/apps_st/data/a_int02.dbf
input datafile file number=00006 name=/d06/UAT/db/apps_st/data/ctxd01.dbf
input datafile file number=00010 name=/d06/UAT/db/apps_st/data/olap.dbf
input datafile file number=00009 name=/d06/UAT/db/apps_st/data/odm.dbf
input datafile file number=00007 name=/d06/UAT/db/apps_st/data/owad01.dbf
channel ORA_DISK_1: starting piece 1 at 11-JAN-14
[root@testerp rman_log]#
backup script is below:
in this script it returns error only at the channel allocaition rest of all backup command i run manually or with scirpt it runs correctly.4
i m not able to know why it returns error only at challnel allocation 1 day before it runs correctly.
[orauat@testerp rman_script]$ cat rman_backup.sh
#!/bin/sh
#ORACLE_SID=UAT
#BACKUP_START_TIME='date +"%y""%m""%d"_"%H""%M""%S"'
#ORACLE_HOME=/d06/UAT/db/tech_st/11.1.0
#PATH=$PATH:${ORACLE_HOME}:${ORACLE_HOME}/bin
#export ORACLE_SID
#export ORACLE_HOME
#export PATH
/d06/UAT/db/tech_st/11.1.0/bin/rman catalog rman/rman007 target sys/sysuat <<EOF
run
allocate channel c1 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_Arch_%c_%U';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system archive log current';
delete expired archivelog all;
crosscheck archivelog all;
backup archivelog all;
delete noprompt archivelog all completed before 'sysdate-4' backed up 1 times to disk;
allocate channel c2 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c3 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c4 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
backup incremental level 1 database;
delete expired backup device type disk;
delete obsolete device type disk;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
exit
EOF
regards
pritesh ranjanyes the script is edited
i have add some command line and edit it for take the full backup level=0 on the same directory with different formant name but location is same.
can i take full backup level 0 and incremental backup level 1 in the same directory with the different format name.
for exp:
allocate channel c2 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c3 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c4 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
i allocate these three channel for incremental level 1 backup;
the backup is done successfully without any error.
after that i have change
allocate channel c2 device type disk format '/d06/UAT/rman_hot_backup/Weekly_backup%d_DB_%c_%U';
allocate channel c3 device type disk format '/d06/UAT/rman_hot_backup/Weekly_backup%d_DB_%c_%U';
allocate channel c4 device type disk format '/d06/UAT/rman_hot_backup/Weekly_backup%d_DB_%c_%U';
backup database incremental level 0
after doing the above changes it get the error. with the channel location.
i have to schedule daily incremental backup level 1 and weekly full backup level 0.
plz suggest me i have to take incremental 1 and full incremental level 0 backup on seperate directory for different format name.
regards
pritesh ranjan -
Scenario:
We have a script that runs a hot backup of each database on a VM server. Because there are multiple databases on the VM we have a mixture of database versions. For example, we might have 8 databases on Server A running 10.2.0.5 and we might have 2 databases on the same server (Server A) running 10.2.0.4 (different homes of course). Our hot backup script sets one single ORACLE_HOME env variable for running a hot backup for all databases.
Question:
Can I safely export the script's ORACLE_HOME as 10.2.0.5 for all the databases on the VM and still get successful hot backups of the 10.2.0.4 and the 10.2.0.5 databases?
Followup Question:
When we eventually start upgrading the 10.2.0.5 databases to 11r2, will a single ORACLE_HOME set by the same hot backup script work knowing that some databases may be 11r2 and some may be 10.2.0.5 on the same VM?
Thanks for your input.The cron job runs a script that builds a script that selects the SIDs on that server and then it runs another script that builds a sqlplus script (script detailed below). The sqlplus script is a file that contains the following commands for each SID on the machine:
set feedback off
set pagesize 0
set termout off
spool /xxx/xxx/b_backup.sql
select 'set termout on' from dual;
select 'set echo on' from dual;
select distinct 'alter tablespace '||tablespace_name||' begin backup;'
from dba_data_files;
select 'select from v$backup;' from dual;*
select 'exit' from dual;
spool off
*@/xxx/xxx/b_backup.sql*
exit
So what we end up with is a sqlplus file that will execute the above commands for each SID on the box. The databases may be different versions though (a mix of 10.2.0.4 and 10.2.0.5).
My basic question is: Will using ORACLE_HOME pointing to 10.2.0.5 sqlplus have any negative effect on backing up a 10.2.0.4 database?
My secondary/follow-up question is concerning future upgrades to 11r2: Will using ORACLE_HOME pointing to 11.2.0.2 sqlplus have any negative effect on backing up the remaining (not yet upgraded) 10.2.0.5 databases?
Does sqlplus version matter when running sqlplus from a different ORACLE_HOME on a database with a different version? -
hello
i am using rman hot backup script to take backup database everyday but the problem is it is working but not deleting old backup older than 2 days .
also i have question .. my database is in archive log mode and everyday about 6-7 .arch files generating in my archive directory.
it is not deleting the old files but generating new files everyday so adding up to the space.
SQL> show parameter archive
NAME TYPE VALUE
archive_lag_target integer 0
log_archive_config string
log_archive_dest string /u03/archive_logs/DEVL
log_archive_dest_1 string
also should i set dest_1 as archive location or just log_archive_dest
whats is the difference.?
my rman script is
RMAN Hot backup.unix script
The RMAN hot backup script rman_backup.sh:
# !/bin/bash
# Declare your environment variables
export ORACLE_SID=DEVL
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=$PATH:${ORACLE_HOME}/bin
# Start the rman commands
rman target=/ << EOF
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u03/backup/autobackup_control_file%F';
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
ALLOCATE CHANNEL RMAN_BACK_CH01 TYPE DISK;
CROSSCHECK BACKUP;
BACKUP AS COMPRESSED BACKUPSET DATABASE FORMAT '/u03/backup/databasefiles_%d_%u_%s_%T';
sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL FORMAT '/u03/backup/archivelogs_%d_%u_%s_%T' DELETE INPUT;
BACKUP AS COMPRESSED BACKUPSET CURRENT CONTROLFILE FORMAT '/u03/backup/controlfile_%d_%u_%s_%T';
CROSSCHECK BACKUP;
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED BACKUP;
RELEASE CHANNEL RMAN_BACK_CH01;
EXIT;
EOF
thanksAhmer Mansoor wrote:
RMAN never deletes the Backups unless there is a space pressure in the Recovery Area. Instead it marks the Backups as OBSOLETE based on Retention Policy (in your case it is 2 Days),
To confirm it SET DB_RECOVERY_FILE_DEST_SIZE to some smaller value, the RMAN will remove all the Obsolete Backups automatically to reclaim space.Be very careful with this. If you generate a LOT of archivelog files and you exceed this size, on the next archivelog switch your database will hang with "cannot continue until archiver freed". RMAN will not automatically remove anything. RMAN only removes stuff when you program it in your script.
See:
http://docs.oracle.com/cd/E14072_01/backup.112/e10642/rcmconfb.htm#insertedID4 Retention Policy (recovery window or redundancy)
things like:
set retention window and number of copies
crosscheck backup
delete obsolete <-- delete old, redundant, no longer necessary backups/archivelogs
delete expired <-- NOTE: If you manually delete files and do not execute delete expired (missing file), the DB_RECOVERY_FILE_DEST_SIZE remains the same. So, you can clean out the space and oracle will still say the location is "full".
Understand that if you also set this parameter too small and your backup recovery window/redundancy are incorrectly set, you can also exhaust the "logical" space of this location again, putting your database at risk. Your parameter could be set to 100G on a 400G file system and even though you have 300G available, Oracle will see the limit of this parameter.
My suggestion, get in a DEV/TEST environment and test to see how to best configure your environment for RMAN database backups/control file, archivelog backups also taking into consideration OS tape backup solutions. I always configure DISK for RMAN backups, then have some other tape backup utility sweep those locations to tape ensuring that I have sufficient backups to reconstitute my database - I also include a copy of the init.ora file, password file as well as the spfile backup in this location.
>
In case of Archivelogs, It is better to create and execute a Purge Job to remove Archivelogs after backup them on tape.I almost agree. I try to keep all archivelogs necessary for recovery from last full backup online. I try to keep a full backup online as well. much faster at restoring stuff instead of trying to locate it on tape. -
Hello, I have a database that takes in between 80 to 600 transactions per day through an external feed. I need to implement a hot backup that will run once a day. I don't need to do point in time recovery because I can restore from the prior nightly backup and then replay the tlog file from the external feed. What is the best way to implement a hot backup. Is it as simple as running a sql procedure that will loop through all the tablespaces and put them in backup mode and then copy them to another location? I am open to all and any recommendations. The database is Oracle 9.2.0.1 running on Windows 2000 or 2003 server. Please provide any scripts if you can. Thank you and have a great day!
DavidI wrote a dynamic hot backup script once, you can look into it if you want:
-- YJAM - Modele backup dynamique
-- SQL*Plus Env
SET TIM OFF TIMI OFF ECHO OFF VERIFY OFF FEED OFF TRIMS ON
-- Variables dépendantes du systeme
DEFINE DEST_DIR=C:\Backup
DEFINE DIR_SEP=\ -- win*=\ | unix=/
DEFINE SH=host -- win*=host | unix=!
DEFINE COPIE=copy -- win*=copy | unix=cp
DEFINE SUPPR=del -- win*=del | unix=rm
DEFINE MARGE_ARCHIVELOGS=10
-- Preparation pour les archives
COL FARCH NEW_VALUE FIRST_ARCHIVELOG NOPRINT;
SELECT MAX(SEQUENCE#)-1 FARCH FROM V$LOG;
PROMPT *************************************************
SET SERVEROUTPUT ON SIZE 200000
SPOOL &DEST_DIR.&DIR_SEP.part1.sql
DECLARE
-- Curseur pour recuperer la liste des datafiles
CURSOR cDatafiles IS SELECT TABLESPACE_NAME, FILE_NAME FROM DBA_DATA_FILES ORDER BY TABLESPACE_NAME;
REP_BACKUP VARCHAR2(500 CHAR) := ''; -- Définition du répertoire principal de destination de sauvegarde
OTN VARCHAR2(50 CHAR) := ' '; -- Variable en aiguillde trainante pour le declanchement du mode backup
PFILE_INFO VARCHAR2(500 CHAR) := ''; -- Variable pour test de type de fichier d'initialisation
BEGIN
-- Validation du repertoire de destination
SELECT INSTANCE_NAME INTO REP_BACKUP FROM V$INSTANCE;
REP_BACKUP := '&DEST_DIR.&DIR_SEP'||REP_BACKUP||'&DIR_SEP'||TO_CHAR(SYSDATE,'YYYYMMDD')||'&DIR_SEP';
DBMS_OUTPUT.PUT_LINE('&SH mkdir ' || REP_BACKUP);
DBMS_OUTPUT.PUT_LINE('--');
-- Traitement des DATAFILEs
FOR vDatafiles IN cDatafiles
LOOP
-- Si le tablespace parcourru n'est pas le meme que le precedent
IF (OTN != vDatafiles.TABLESPACE_NAME) THEN
-- Si ce n'est pas le premier alors on bascule l'ancien hors du mode backup
IF (OTN != ' ') THEN
DBMS_OUTPUT.PUT_LINE('ALTER TABLESPACE ' || OTN || ' END BACKUP;');
END IF;
-- Mise a jour de l'aiguillde trainante et mise en mode backup du tablespace
OTN := vDatafiles.TABLESPACE_NAME;
DBMS_OUTPUT.PUT_LINE('ALTER TABLESPACE ' || OTN || ' BEGIN BACKUP;');
END IF;
-- Il faut sauvegarder les fichiers!
DBMS_OUTPUT.PUT_LINE('&SH &COPIE ' || vDatafiles.FILE_NAME || ' ' || REP_BACKUP);
END LOOP;
-- Evite un effet de bord: sortir le dernier tablespace du mode backup*
DBMS_OUTPUT.PUT_LINE('ALTER TABLESPACE ' || OTN || ' END BACKUP;');
DBMS_OUTPUT.PUT_LINE('--');
-- Sauvegarde du fichier de controle sous forme controlfile et trace
DBMS_OUTPUT.PUT_LINE('ALTER DATABASE BACKUP CONTROLFILE TO ''' || REP_BACKUP || 'control.ctl'';');
DBMS_OUTPUT.PUT_LINE('ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS ''' || REP_BACKUP || 'trace.ctl'';');
DBMS_OUTPUT.PUT_LINE('--');
-- Vérification du type de fichier d'initialisation
SELECT VALUE INTO PFILE_INFO FROM V$PARAMETER WHERE NAME='ifile';
IF (PFILE_INFO IS NULL) THEN
-- A priori on utilise un fichier de type SPFILE ou le PFILE standard
SELECT VALUE INTO PFILE_INFO FROM V$PARAMETER WHERE NAME='spfile';
IF (PFILE_INFO IS NULL) THEN
-- On utilise le pfile standard
-- Donc on créée temporairement un spfile pour en faire une sauvegarde)
DBMS_OUTPUT.PUT_LINE('CREATE SPFILE=''' || REP_BACKUP || 'spfile.ora'' FROM PFILE;');
DBMS_OUTPUT.PUT_LINE('CREATE PFILE=''' || REP_BACKUP || 'pfile.ora'' FROM SPFILE=''' || REP_BACKUP || 'spfile.ora'';');
DBMS_OUTPUT.PUT_LINE('&SH &SUPPR ' || REP_BACKUP || 'spfile.ora');
ELSE
-- On utilise un spfile
-- Donc on le sauvegarde simplement
DBMS_OUTPUT.PUT_LINE('CREATE PFILE=''' || REP_BACKUP || 'pfile.ora'' FROM SPFILE;');
END IF;
ELSE
-- on utilise un pfile specifique
DBMS_OUTPUT.PUT_LINE('&SH &COPIE ' || PFILE_INFO || ' ' || REP_BACKUP);
END IF;
DBMS_OUTPUT.PUT_LINE('--');
END;
SPOOL OFF
@&DEST_DIR.&DIR_SEP.part1.sql
PROMPT *** Exec part 1
SPOOL &DEST_DIR.&DIR_SEP.part2.sql
DECLARE
-- urseur de parcours de la liste des archivelogs
CURSOR cListearchive(pLow NUMBER, pHigh NUMBER) IS SELECT NAME,SEQUENCE#
FROM V$ARCHIVED_LOG
WHERE SEQUENCE# BETWEEN pLow AND pHigh
AND DEST_ID IN
(SELECT DEST_ID
FROM V$ARCHIVE_DEST
WHERE DESTINATION IS NOT NULL
AND UPPER(DEST_NAME) IN
(SELECT UPPER(NAME)
FROM V$PARAMETER
WHERE VALUE IS NOT NULL
AND NAME LIKE '%log_archive_dest_%'
AND UPPER(SUBSTR(VALUE,1,8))='LOCATION'
ORDER BY SEQUENCE#;
LAST_ARCHIVELOG NUMBER := 0;
-- Variables de bornage des archives a sauvegarder
FIRST_ARCHIVELOG NUMBER := &FIRST_ARCHIVELOG;
CURR_ARCHIVELOG NUMBER := 0;
REP_BACKUP VARCHAR2(500 CHAR) := '';
-- Définition du répertoire principal de destination de sauvegarde
BEGIN
-- Validation du repertoire de destination
SELECT INSTANCE_NAME INTO REP_BACKUP FROM V$INSTANCE;
REP_BACKUP := '&DEST_DIR.&DIR_SEP'||REP_BACKUP||'&DIR_SEP'||TO_CHAR(SYSDATE,'YYYYMMDD')||'&DIR_SEP';
-- Marge de travail sur les fichiers archivelogs
EXECUTE IMMEDIATE 'ALTER SYSTEM SWITCH LOGFILE';
-- On va savegarder les &MARGE_ARCHIVELOGS derniers archivelogs.
SELECT MAX(SEQUENCE#)-1 INTO LAST_ARCHIVELOG FROM V$LOG;
FIRST_ARCHIVELOG := FIRST_ARCHIVELOG - &MARGE_ARCHIVELOGS;
DBMS_OUTPUT.PUT_LINE('-- tranche: ' || FIRST_ARCHIVELOG || ' a ' || LAST_ARCHIVELOG);
-- Parcours de la liste des elements archives concernes
FOR vListearchive IN cListearchive(FIRST_ARCHIVELOG,LAST_ARCHIVELOG)
LOOP
-- Traite t'on une nouvelle archive?
IF (CURR_ARCHIVELOG != vListearchive.SEQUENCE#) THEN
DBMS_OUTPUT.PUT_LINE('&SH &COPIE ' || vListearchive.NAME || ' ' || REP_BACKUP);
CURR_ARCHIVELOG := vListearchive.SEQUENCE#;
END IF;
-- si non il n'y a rien à faire.
END LOOP;
END;
SPOOL OFF
PROMPT *** Exec part 2
@&DEST_DIR.&DIR_SEP.part2.sql
PROMPT *************************************************But it's provided without guarantee. It's been a long time i've not used it! And it might have bugs. Up to you to test it, backup is not a matter where you trust people :-)
Of course, you could also use a simple RMAN script, depending on what you are trying to achieve exactly:
RUN
allocate channel c01 type disk format 'c:\backup\%d%U';
backup database;
backup archivelog all delete input;
}This is just a sample. And you need to choose how you'll use RMAN.
Yoann.
Edited to clean up the code from unnecessary blank lines...
Message was edited by:
Yoann Mainguy -
I have a hot backup script for single-instance.
Any one who want to explain me points to take care in a hot backup for RAC environment?Hello,
I am sorry to bring this up again since it was last posted on Feb 2007. Does anyone know exactly how to perform user managed backup or at least convince me not to use it in a RAC environment? For example, if my storage array has the snapshot capability and I run Oracle10g RAC on Linux with two nodes cluster using OCFS2 (file systems), can't I just put the database in online backup mode for both instances and just take a snapshot of my Linux volumes? The reason is that I create one shared volume for database datafiles, and one shared volume for online redo logs, and one shared volume for archived logs, in a RAC environment, if one instance fail, then the database is still OK, but if a datafile is missing, then I can just startup one instance, recover the datafile, and then restart the other instance. Is this OK or am I smoking something? Please explain.
Thank you,
TD -
Win2000/NT hot back script
Can someone provide a basci script for online(hot) backup for Oracle9i(8i) on Windows2000/NT server? we have a online application, and plan to back it up every night.
Also, Windows should have administrative tool to schedule the backup by envoking the script every night after we set it up, right?
Many THANKS for your help!!!Hope this solves ur problem
Run this script through SQLPLUS and it will ask you for the
HOT_BACK_DIR and GEN_FILE values.
HOT_BACK_DIR : defines the directory to which the hot backup is written
SCRIPT_FILE : Hot Backup Script for your environment
INT_PWD :Internal Password ( Needed for NT Only )
Give me the Credit and never use it without askin me ;)
****************************** DO NOT DELETE*********************/
define HOT_BACK_DIR = &1
define SCRIPT_FILE = &2
define INT_PWD = &3
/* Create Temporary Table with Tablespace Data */
drop table dsc_hot_stage;
create table dsc_hot_stage
tablespace_name varchar2(30),
file_name varchar2(200)
insert into dsc_hot_stage
select rtrim(tablespace_name),rtrim(file_name) from sys.dba_data_files;
/**** Set up the parameters for the spool file */
set feedback off
set heading off
set pagesize 0
set linesize 128
set verify off
set termout oN
set echo off
spool &SCRIPT_FILE
select '/* ',
'**** This is the hot backup script and has been generated',
'**** by gen_hot_dos.sql.',
'**** ' || to_char(sysdate, 'MM/DD/YYYY HH:MI:SS') ,
'**** You are Allowed to Use this script freely as long '
'**** as this title is not deleted
'**** For more Scripts Visit DBASUPPORT.COM */'
from dual;
select 'connect internal/&3' from dual;
-- Create Script to backup Control File to Trace
select 'alter database backup controlfile to trace; '
from dual;
-- Create Script to backup actual files to a directory
select 'alter tablespace '|| tablespace_name||' begin backup;' c1,
'host ocopy80 '||file_name||' &HOT_BACK_DIR' || '\' ||
substr(file_name,instr(rtrim(file_name),'\',-1,1)+1,length(rtrim(file_name)))||
'.bak' c2
from dsc_hot_stage
union
select 'alter tablespace '|| tablespace_name||' end backup;' c1,
null c2,
from dsc_hot_stage
group by tablespace_name,file_name order by 1;
select 'exit' from dual;
spool off -
RMAN script for hot backup (looking for code critic) code attached.
Hello Guru's,
I have been having soem trouble running a successful hot full rman backup nightly.
We max our CPU load whenever our RMAN takes too long and conflicts with a Legato tape backup. I have a development server that I attempted to get a consistent backup time duration that is rock solid as to not conflict with the Legato backup time.
I just found out about duration with RMAN scripts here is my code:
#!/bin/bash
#rman backup script for daily hot whole database backup
at -f /hd1/rman_scripts/rman_backup 0600 tomorrow
rman target/
run {
allocate channel d1 device type disk format '/path/%U';
backup duration 1:00 partial minimize load database filesperset 1;
backup as BACKUPSET tag '%TAG' database;
backup as BACKUPSET tag '%TAG' archivelog all delete all input;
delete noprompt obsolete;
release channel d1;
exit
It completes the backup, but does not use the 1 hour allocated- it only uses 15 minutes on average and creates many files instead of normally three backup files.
Here is the results from querying the v$rman_status table for operation,status,start_time:
RMAN,FAILED, 17-OCT-06 0600
BACKUP,FAILED,17-OCT-06 0600
RMAN,FAILED,17-OCT-06 0606
BACKUP,COMPLETED,17-OCT-06 0606
BACKUP,COMPLETED,17-OCT-06 0606
BACKUP,FAILED,17-OCT-06 0615
RMAN,COMPLETED,17-OCT-06 1513
REPORT,COMPLETED,17-OCT-06 1513
DELETE,COMPLETED,17-OCT-06 1513
However, the timestamps of the backupset files it creates is:
06:15 and not 1513?????????????
RMAN appears to have only taken 15 minutes to create the files, why do I have a completed timestamp from v$rman_status of 1513???
Please advise and comment, I am just learning RMAN.Try to remove the DURATION option in your script.
Here more details about that part.
http://download-east.oracle.com/docs/cd/B19306_01/backup.102/b14194/rcmsynta009.htm#i1010261
Bye, Aron -
Shell scripting for hot backup
Hi,
can you please give me shell scripting and it's explanation for taking hot backup. and which shell scripts are frequently use in real time.
thank a lot in advance.HAve you ever heard about RMAN ? Much better than reinvent the wheel.
http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/rcmquick.htm
Nicolas. -
RMAN script for RAC Hot Backup
Anyone who want to share an RMAN script to Hot Backup a 9i RAC Database.
Try to remove the DURATION option in your script.
Here more details about that part.
http://download-east.oracle.com/docs/cd/B19306_01/backup.102/b14194/rcmsynta009.htm#i1010261
Bye, Aron -
hi,
please help me to take hot backup.
i want step by step procedure or send me some links
with regards,
SenthilkumarpI think you'd be better asking about backups in the correct forum...
Try...
General Database Discussions
or
Recovery Manager (RMAN) -
How to find out which archived logs needed to recover a hot backup?
I'm using Oracle 11gR2 (11.2.0.1.0).
I have backed up a database when it is online using the following backup script through RMAN
connect target /
run {
allocate channel d1 type disk;
backup
incremental level=0 cumulative
filesperset 4
format '/san/u01/app/backup/DB_%d_%T_%u_%c.rman'
database
}The backup set contains the backup of datafiles and control file. I have copied all the backup pieces to another server where I will restore/recover the database but I don't know which archived logs are needed in order to restore/recover the database to a consistent state.
I have not deleted any archived log.
How can I find out which archived logs are needed to recover the hot backup to a consistent state? Can this be done by querying V$BACKUP_DATAFILE and V$ARCHIVED_LOG? If yes, which columns should I query?
Thanks for any help.A few ways :
1a. Get the timestamps when the BACKUP ... DATABASE began and ended.
1b. Review the alert.log of the database that was backed up.
1c. From the alert.log identify the first Archivelog that was generated after the begin of the BACKUP ... DATABASE and the first Archivelog that was generated after the end of the BACKUP .. DATABASE.
1d. These (from 1c) are the minimal Archivelogs that you need to RECOVER with. You can choose to apply additional Archivelogs that were generated at the source database to contininue to "roll-forward"
2a. Do a RESTORE DATABASE alone.
2b. Query V$DATAFILE on the restored database for the lowest CHECKPOINT_CHANGE# and CHECKPOINT_TIME. Also query for the highest CHECKPOINT_CHANGE# and CHECKPOINT_TIME.
2c. Go back to the source database and query V$ARCHIVED_LOG (FIRST_CHANGE#) to identify the first Archivelog that has a higher SCN (FIRST_CHANGE#) than the lowest CHECKPOINT_CHANGE# from 2b above. Also query for the first Archivelog that has a higher SCN (FIRST_CHANGE#) than the highest CHECKPOINT_CHANGE# from 2b above.
2d. These (from 2c) are the minimal Archivelogs that you need to RECOVER with.
(why do you need to query V$ARCHIVED_LOG at the source ? If RESTORE a controlfile backup that was generated after the first Archivelog switch after the end of the BACKUP ... DATABASE, you would be able to query V$ARCHIVED_LOG at the restored database as well. That is why it is important to force an archivelog (log switch) after a BACKUP ... DATABASE and then backup the controlfile after this -- i.e. last. That way, the controlfile that you have restored to the new server has all the information needed).
3. RESTORE DATABASE PREVIEW in RMAN if you have the archivelogs and subsequent controlfile in the backup itself !
Hemant K Chitale
Maybe you are looking for
-
Comcast Internet connection no longer works with Airport Express
This is a little bit out of my depth, so I'm hoping that someone can help me. I've been accessing Comcast High Speed Internet through my Airport Express connection for more than a year. Things were great until last week when my connection stopped wor
-
Privacy Settings on MacBook Pro
I'm trying to change a security setting on my MacBook Pro to allow an app to be downloaded. The lock in the corner is locked but when I try to unlock it, it stays locked. I'm logged in as administrator and have opened the lock under Users. Why can't
-
Help my mouse doesn't function
Help!, my mouse doesn't react anymore. It can move but when i click it does nothing. Tried it with an USB-mouse, wireless mouse and the trackpad on the macbook itself
-
Error when opening GW Mail Icon on a Palm T2
When I try to open the GW Mail icon on a Tungsten E2 palm I get an error message of " A problem was wncounted reading the groupwise folder list Verify that your Groupwise account does not have any corrupt or damaged folders". I see it synce up and pu
-
Flatten Bates numbers in a batch mode?
How does one flatten all Bates numbered documents in a batch mode?