center.bat --總的調度中心,設置環境變量,調用其餘腳本 @echo off echo ================================================ echo Windows環境下Oracle數據庫的自動清理歸檔腳本 echo 刪除已成功應用的備庫的歸檔日誌 echo ================================================ ::以「YYYYMMDD」格式取出當前時間。 SET BACKUPDATE=%date:~0,4%-%date:~5,2%-%date:~8,2% SET ORACLE_HOME=E:\app\Administrator\product\11.2.0\dbhome_1 SET ORACLE_SID=mes SET NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS" SET LOG_DIR=E:\rman\del_arch_log SET LOG_NAME=%LOG_DIR%\del_adg_arc_%ORACLE_SID%_%BACKUPDATE%.log SET SQL_NAME=%LOG_DIR%\del_adg_arc.sql sqlplus -s sys/oracle@mes as sysdba @E:\\rman\pro_sql.bat rman target sys/oracle@mes cmdfile='E:\rman\del_arc.bat' LOG=%LOG_NAME% pro_sql.bat --生成刪除歸檔的語句到指定目錄並保存成SQL腳本,此處是刪除全部應用過的歸檔日誌,如需保留幾天,修改數字0 set feedback off heading off pagesize 0 linesize 100 col exec_sql format a50 spool %SQL_NAME% SELECT 'delete archivelog sequence ' || A.SEQUENCE# || ' thread ' || A.THREAD# || ';' EXEC_SQL FROM V$ARCHIVED_LOG A WHERE (A.THREAD#, A.SEQUENCE#, a.RESETLOGS_CHANGE#) IN (SELECT b.THREAD#, b.SEQUENCE#, b.RESETLOGS_CHANGE# FROM V$ARCHIVED_LOG B WHERE B.APPLIED = 'YES' AND b.COMPLETION_TIME <= SYSDATE - 0) AND a.NAME NOT IN (SELECT b.DESTINATION FROM v$archive_dest b WHERE b.DESTINATION IS NOT NULL) AND A.COMPLETION_TIME <= SYSDATE - 0 ORDER BY A.THREAD#, A.SEQUENCE#; spool off exit; del_arc.bat --清理歸檔日誌並調用上段中生成的SQL腳本 crosscheck archivelog all; delete noprompt expired archivelog all; @E:\rman\del_arch_log\del_adg_arc.sql exit; exit;