@echo off
setlocal enabledelayedexpansion
title %date% %time:~,8% by LiaoNing Sunray Software Technology
::XXX数据库备份
::定义数据库SID
set SID=orcl
::定义用户名数组(各用户间用空格分隔 例如:user1 user2 user3)
set userArr=aaa
set pswdArr=bbb
::指定删除天数
set daysAgo=3
::指定备份路径
set filePath=D:\Oracle数据库备份\
::定义脚本内部变量
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%\
::创建以当天日期命名的文件夹
if not exist %filePath% md %filePath%
if not exist %filePath%%newDir% md %filePath%%newDir%
echo 开始备份(备份整个数据库).....
exp %userArr%/%pswdArr%@%SID% file=%filePath%%newDir%%userArr%_%fileName%
::删除N天以前的数据
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%‘) do (
set t2=%%i
set t3=!t2:~0,10!
if !t3! lss !t1! rd /s/q "%filePath%%%i")
del /f temp.txt