自动备份的代码:
REM #####################################
REM # 数据库自动备份脚本
REM #####################################
REM 取当前系统时间,操作系统不同取到的值可能不一样,需要调试
set CURDATE=%date:~0,4%%date:~5,2%%date:~8,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
REM 创建备份用目录,目录结构为backup/YYYYMMDD/HH/
if not exist "backup" mkdir backup
if not exist "backup/%CURDATE%/" mkdir backup/%CURDATE%/
if not exist "backup/%CURDATE%/%CURTIME%" mkdir backup/%CURDATE%/%CURTIME%
set CURDIR=backup/%CURDATE%/%CURTIME%
set FILENAME=%CURDIR%/BAK
REM 调用ORACLE的exp命令导出用户数据
exp user/pwd@ORCL_192.168.1.1 file=%FILENAME% log=%FILENAME% owner=user
exit
以上脚本配合windows的“任务计划”,可以实现定时导出指定用户的数据,从而达到备份的目的。
注:
REM =============================================================
REM 删除超过指定期限的目录(目录结构必须为:backup/YYYYMMDD/),
REM 其中YYYYMMDD为以年月日命名的目录,
REM 该脚本将自动删除超过指定期限的YYYYMMDD目录
REM =============================================================
ECHO OFF
REM 设定期限
set DELAY_DAY=-30
echo wscript.echo dateadd("d",%DELAY_DAY%,date) >%tmp%/tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%/tmp.vbs') do set y=%%i
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%/tmp.vbs') do set m=%%j
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%/tmp.vbs') do set d=%%k
REM if %m% LSS 9 set m=0%m%
REM if %d% LSS 9 set d=0%d%
if "%m%"=="0" set m=00
if "%m%"=="1" set m=01
if "%m%"=="2" set m=02
if "%m%"=="3" set m=03
if "%m%"=="4" set m=04
if "%m%"=="5" set m=05
if "%m%"=="6" set m=06
if "%m%"=="7" set m=07
if "%m%"=="8" set m=08
if "%m%"=="9" set m=09
if "%d%"=="0" set d=00
if "%d%"=="1" set d=01
if "%d%"=="2" set d=02
if "%d%"=="3" set d=03
if "%d%"=="4" set d=04
if "%d%"=="5" set d=05
if "%d%"=="6" set d=06
if "%d%"=="7" set d=07
if "%d%"=="8" set d=08
if "%d%"=="9" set d=09
set LASTDATE=%y%%m%%d%
set OLDDIR=backup/%LASTDATE%
echo start del dir /%OLDDIR%...
rd/s/q %OLDDIR%
exit