@echo off
Setlocal enabledelayedexpansion
Title%date%%time:~,8% by Liaoning Sunray Software Technology
:: XXX Database backup
:: Define Database SID
Set SID=ORCL
:: Define user an array groups (spaces separated by each user for example: User1 user2 User3)
Set USERARR=AAA
Set PSWDARR=BBB
:: Specify the number of days to delete
Set daysago=3
:: Specify the backup path
Set Filepath=d:\oracle database backup \
:: Define script internal variables
Set Time_=%time: =0%
Set Filename=%date:~0,4%%date:~5,2%%date:~8,2%_%time_:~0,2%%time_:~3,2%.dmp
Set newdir=%date:~0,10%\
:: Create a folder named after today's date
If not exist%filepath% MD%filepath%
If not exist%filepath%%newdir% MD%filepath%%newdir%
Echo starts backup (backs up the entire database) .....
Exp%userarr%/%pswdarr%@%sid% file=%filepath%%newdir%%userarr%_%filename%
:: Delete data from N days ago
Set d=%date:~0,10%
Mshta vbscript:createobject ("Scripting.FileSystemObject"). OpenTextFile ("Temp.txt", 2,true). Write (FormatDateTime ( DATEADD ("D",-%daysago%+1, "%d%"), Vbshortdate)) (Window.close)
for/f "Tokens=1 delims="%%i in (temp.txt) do set t1=%%i
for/f "delims="%%i in (' dir/ad/b%filepath% ') does (
Set t2=%%i
Set t3=!t2:~0,10!
If!t3! LSS!t1! rd/s/q "%filepath%%%i")
del/f Temp.txt
Oracle 11g Database Automatic backup execution script