熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

oracle數據庫備份與恢復apieceofcake(4)

2022-06-13   來源: Oracle 

  oracle數據庫日志備份(windows平台)

  本片是接上次的數據庫在線備份進行數據庫全備份後需要備份歸檔的日志文件

   建立數據庫備份的腳本

  在上面建立的目錄下建立如下的兩個腳本

   建立執行備份任務的腳本(批處理文件)

  文件內容如下

  @echo OFF
    Rem ===========================================================================
    Rem  NAME     archive_backup_Runbat
    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    //   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%\ora
    set ORACLE_DATA=%ORACLE_BASE%\oradata\%ORACLE_SID%
    set ORACLE_ADMIN=%ORACLE_BASE%\admin\%ORACLE_SID%

  %ORACLE_HOME%\bin\sqlplus /nolog @archive_backupsql > archive_backuplog

   建立完成備份認為的命令文件(sqlplus內執行的sql腳本)

  文件內容如下

  Rem =====================================================================================
    Rem  NAME     archive_backupsql
    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 //
    Rem =====================================================================================

  Rem Set SQL*Plus variables to manipulate output
    set feedback off
    set pagesize
    set heading off
    set verify off
    set linesize
    set trimspool on

  Rem Set SQL*Plus user variables used in script
    define adm = sys
    define pwd = oraclei

  Rem  for Windows
    define dir = C:\oracle\admin\TSTDB\backup\archive log
    define fil = archive_backup_commandssql
    define spo = archive_backup_outputlst
    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)
              AND completion_time < trunc(sysdate);

  prompt spool off;;
    spool off;

  Rem Run the copy file commands from the operating system
    rem @&
    exit;

   修改教本定義的變量
   
    在運行教本中定義的一些變量將其改為本地數據庫安裝環境的變量
   
    需要修改的變量有
   
    在close_Backup_runbat腳本中
      set ORACLE_SID=TSTDB
      set ORACLE_CONNECTSTRING=tstdb
      set ORACLE_BASE=c:\oracle
      set ORACLE_HOME=%ORACLE_BASE%\ora
     
    在close_backupsql腳本中
      define adm = sys
      define pwd = oraclei
      define dir = C:\oracle\admin\TSTDB\backup
      define ctl = &dir\controlctl

   執行數據庫備份任務

  在$ORACLE_BASE\admin\admin_script目錄下運行open_Backup_runbat

   執行自動備份

  在windows系統中添加計劃任務定期運行open_Backup_runbat


From:http://tw.wingwit.com/Article/program/Oracle/201311/17887.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.