Windows Server系統定時任務備份ORACLE數據庫

Windows Server系統定時任務備份ORACLE數據庫sql

1、編輯備份腳本

RMAN備份數據庫

一、在備份腳本目錄下,建立bat文件db_rman.bat數據庫

 set ORACLE_SID=orcl1windows

D:\app\admin\product\11.2.0\dbhome_1\binsession

rman target /  cmdfile=D:/dbback/db_scripts/db_rman.txt log=D:/dbback/db_scripts/db_%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%.log app

 FORFILES /P D:/dbback/db_scripts /M *.log /D -30 /C "cmd /c del @path"spa

exit操作系統

 二、建立rman備份腳本db_rman.txt文件orm

sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';blog

run { ip

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

CONFIGURE BACKUP OPTIMIZATION ON;

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'D:/dbback/db_rman/%F.ctl';

backup tag 'dbfull' format 'D:/dbback/db_rman/full%u_%s_%p' database;

sql 'alter system archive log current';

backup archivelog all format 'D:/dbback/db_rman/arc_%T_%U.arg';

 

delete noprompt expired archivelog all;

delete noprompt archivelog all completed before 'sysdate-14';

delete noprompt obsolete;

delete noprompt expired backup;

 

list backup summary;

exit; 

EXPDP備份數據庫

在備份腳本目錄下編輯定時任務db_expdp.bat

@echo off 

REM ########################################################### 

REM # Windows Server下Oracle數據庫自動備份批處理腳本

REM # 使用expdb命令導出須要先在數據庫中建立備份文件存貯目錄

REM ########################################################### 

REM 取當前系統時間,可能因操做系統不一樣而取值不同 

set CURDATE=%date:~0,4%%date:~5,2%%date:~8,2%

set CURMON=%date:~0,4%%date:~5,2%

set CURTIME=%time:~0,2%

REM 小時數若是小於10,則在前面補0 

if "%CURTIME%"==" 0" set CURTIME=00

if "%CURTIME%"==" 1" set CURTIME=01

if "%CURTIME%"==" 2" set CURTIME=02

if "%CURTIME%"==" 3" set CURTIME=03

if "%CURTIME%"==" 4" set CURTIME=04

if "%CURTIME%"==" 5" set CURTIME=05

if "%CURTIME%"==" 6" set CURTIME=06

if "%CURTIME%"==" 7" set CURTIME=07

if "%CURTIME%"==" 8" set CURTIME=08

if "%CURTIME%"==" 9" set CURTIME=09

set CURTIME=%CURTIME%%time:~3,2%%time:~6,2%

REM 設置全部者、用戶名和密碼 

set OWNER=orcl

set USER=dba

set PASSWORD=manager

REM 建立備份用目錄,目錄結構爲F:\expdpbak

 

set FILENAME=%OWNER%_%CURDATE%_%CURTIME%.dmp

set EXPLOG=%OWNER%_%CURDATE%_%CURTIME%.log 

expdp %USER%/%PASSWORD%@%OWNER% DIRECTORY=DUMP_DIR DUMPFILE=%FILENAME% LOGFILE=%EXPLOG%

FORFILES /P F:\expdpbak /M *.dmp /D -30 /C "cmd /c del @path"

FORFILES /P F:\expdpbak /M *.log /D -30 /C "cmd /c del @path"

exit

 EXP/IMP備份數據庫

set filename=d:/db_backup/db_expdp/scott_%date:~0,4%%date:~5,2%%date:~8,2%
exp scott/tiger file=%filename%.dmp log=%filename%.log

FORFILES /P D:\db_backup\db_expdp /M *.dmp /D -15 /C "cmd /c del @path"
FORFILES /P D:\db_backup\db_expdp /M *.log /D -15 /C "cmd /c del @path"
exit

2、編輯定時任務(RMAN備份數據庫)

 

建立任務,輸入定時任務名稱

 

 

新建觸發器,設置天天23:30:00開始任務

 

 

新建操做,選定備份定時任務腳本.bat

 

 

條件選項,默認

 

 

設置選項,設定任務運行時間超過如下時間,即12小時,中止任務

 

 

 

 windows下expdp腳本

#FORFILES /P E:\bak /M *.dmp /D -2 /C "cmd /c del @path"
#刪除E:\bak目錄下.dmp結尾的3天前的文件

set ORACLE_SID=orclset dumpfile=dmp%date:~0,4%%date:~5,2%%date:~8,2%%%U.dmpset logfile=dmp%date:~0,4%%date:~5,2%%date:~8,2%.logset syncfile=dmp%date:~0,4%%date:~5,2%%date:~8,2%set insert_head=insert into BACK_USER.sync_file_list (db_ip,INCREMENTAL_LEVEL,file_name,pwd_name,handle,back_completion_time,sync_status) values('10.86.240.10','0',e:cd E:\Oracle\app\Administrator\product\11.2.0\dbhome_1\BINexpdp \"/ as sysdba\" directory=DIRECTORY_NAME dumpfile=%dumpfile% logfile=%logfile% EXCLUDE=STATISTICS parallel=8 compression=all schemas=HIS,CIS filesize=2GFORFILES /P F:\expdpbak /M *.dmp /D -6 /C "cmd /c del @path"FORFILES /P F:\expdpbak /M *.log /D -6 /C "cmd /c del @path"exit

相關文章
相關標籤/搜索