oracle資料庫備份與恢復 a piece of cake (4)(轉)

post0發表於2007-08-10
oracle資料庫備份與恢復 a piece of cake (4)(轉)[@more@]

oracle資料庫日誌備份:(windows平臺)

本片是接上次的資料庫線上備份,進行資料庫全備份後需要備份歸檔的日誌檔案。

1. 建立資料庫備份的指令碼

在上面建立的目錄下建立如下的兩個指令碼。

1.1 建立執行備份任務的指令碼(批處理檔案)

檔案內容如下:

@echo OFF

Rem ===========================================================================

Rem NAME - archive_backup_Run.bat

Rem FUNCTION - Creates a backup script for a User Managed backup

Rem NOTES - This script will create a script and run OS copy commands

Rem on closed (cold) database

Rem MODIFIED - ksmith 01/01/02 Original File

Rem ===========================================================================

Rem For Windows, set environment variables for the root path.

set ORACLE_SID=TSTDB

set ORACLE_CONNECTSTRING=tstdb

set ORACLE_BASE=c:oracle

set ORACLE_HOME=%ORACLE_BASE%ora92

set ORACLE_DATA=%ORACLE_BASE%oradata\%ORACLE_SID%

set ORACLE_ADMIN=%ORACLE_BASE%admin\%ORACLE_SID%

%ORACLE_HOME%insqlplus /nolog @archive_backup.sql > archive_backup.log

1.2 建立完成備份認為的命令檔案(sqlplus內執行的sql指令碼)

檔案內容如下:

Rem =====================================================================================

Rem NAME - archive_backup.sql

Rem FUNCTION - Creates a backup command file for a User Managed Archive Log backup

Rem NOTES - This script will create a script and run OS copy commands

Rem on an open or closed database.

Rem MODIFIED - Mr. Tianliang Guo 2002/08/19

Rem =====================================================================================

Rem Set SQL*Plus variables to manipulate output

set feedback off

set pagesize 0

set heading off

set verify off

set linesize 150

set trimspool on

Rem Set SQL*Plus user variables used in script

define adm = 'sys'

define pwd = 'oracle9i'

Rem for Windows

define dir = 'C:oracleadminTSTDBackuparchive log'

define fil = 'archive_backup_commands.sql'

define spo = 'archive_backup_output.lst'

define cpy = 'copy'

Rem login database

connect &adm/&pwd as sysdba;

Rem Create a file containing all the file copy commands needed for open physical backup

spool &

prompt spool &;

prompt alter system archive log all;;

SELECT 'host &cpy '||name||' &dir'

FROM v$archived_log

WHERE completion_time >= trunc(sysdate)-1

AND completion_time < trunc(sysdate);

prompt spool off;;

spool off;

Rem Run the copy file commands from the operating system

rem @&

exit;

2. 修改教本定義的變數

在執行教本中定義的一些變數,將其改為本地資料庫安裝環境的變數。

需要修改的變數有,

在close_Backup_run.bat指令碼中:

set ORACLE_SID=TSTDB

set ORACLE_CONNECTSTRING=tstdb

set ORACLE_BASE=c:oracle

set ORACLE_HOME=%ORACLE_BASE%ora81

在close_backup.sql指令碼中:

define adm = 'sys'

define pwd = 'oracle8i'

define dir = 'C:oracleadminTSTDBackup'

define ctl = '&dircontrol.ctl'

3. 執行資料庫備份任務

在$ORACLE_BASEadminadmin_script目錄下執行open_Backup_run.bat

4. 執行自動備份

在windows系統中新增計劃任務,定期執行open_Backup_run.bat

如果你有問題可以聯絡:

站內的簡訊:ganku

mail: peter_guo@pub.szedi.com.cn

guo_tianliang@yahoo.co

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8225414/viewspace-942640/,如需轉載,請註明出處,否則將追究法律責任。

相關文章