转:oracle自动备份shell

@echo off
setlocal enabledelayedexpansion
title %date% %time:~,8% by LiaoNing Sunray Software Technology

::定义数据库SID
set SID=sryx254

::定义用户名数组(各用户间用空格分隔 例如:wy eit ryx)
set userArr=tiany eit eio ryx
set pswdArr=tiany eit eio ryx

::指定删除天数
set daysAgo=7

::指定备份路径
set filePath=E:\dmp_beifen\


::定义脚本内部变量
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%

::导出数据
set/a n=1
call :sub userArr %userArr%
call :sub pswdArr %pswdArr%
set/a arrLength=nuserArr
:loop
exp !userArr%n%!/!pswdArr%n%!@%SID% file=%filePath%%newDir%!userArr%n%!_%fileName%
::echo 测试显示 !userArr%n%!/!pswdArr%n%!
if %n% lss %arrLength% set/a "n+=1"&goto loop
goto next
:sub
set %1%n%=%2
if not "%3"=="" (set/a n+=1
  shift /2&goto sub)
set/a "n%1=n,n=1"&goto :eof
:next


::删除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

你可能感兴趣的:(oracle)