windows下oracle数据库定时备份与压缩批处理脚本(win7/win2008亲测通过)

第一种方式:全备份,并直接覆盖原来的备份文件,固定命名。

脚本:

@echo off

exp system/a123@HZPG file=e:\db_backup\oradata.dmp log=e:\db_backup\oradata.log

echo 备份成功!

 

第二种方式:全备份,以日期命名。此方法来自:http://www.cnblogs.com/xwdreamer/archive/2011/07/15/2296980.html

脚本:

@echo off

set hour=%time:~,2%

if "%time:~,1%"==" " set hour=0%time:~1,1%

set temp=%date:~0,4%-%date:~5,2%-%date:~8,2%-%hour%-%time:~3,2%-%time:~6,2%

exp system/a123@HZPG file=e:\db_backup\oradata_%temp%.dmp log=e:\db_backup\oradata_%temp%.log

echo 备份成功!

pause

 

第三种方式:全备份,保留七天的备份数据。此方法来自:http://www.cnblogs.com/xwdreamer/archive/2011/07/15/2296980.html

脚本:

del e:\db_backup\oradata7.dmp 

del e:\db_backup\oradata7.log

ren e:\db_backup\oradata6.dmp oradata7.dmp 

ren e:\db_backup\oradata5.dmp oradata6.dmp 

ren e:\db_backup\oradata4.dmp oradata5.dmp 

ren e:\db_backup\oradata3.dmp oradata4.dmp 

ren e:\db_backup\oradata2.dmp oradata3.dmp 

ren e:\db_backup\oradata.dmp oradata2.dmp 

ren e:\db_backup\oradata6.log oradata7.log 

ren e:\db_backup\oradata5.log oradata6.log 

ren e:\db_backup\oradata4.log oradata5.log 

ren e:\db_backup\oradata3.log oradata4.log 

ren e:\db_backup\oradata2.log oradata3.log 

ren e:\db_backup\oradata.log oradata2.log

exp system/a123@HZPG file=e:\db_backup\oradata.dmp log=e:\db_backup\oradata.log 

 

第四种方式:全备份,备份好后立即压缩,保留七天的备份数据,压缩包及数据库文件均以时间命名。

由于项目中是每天备份一次,所以要删除七天前的备份文件,只需判断当前的压缩包等于8时,按创建时间顺序排列压缩包,然后删除最后一个即可实现。详见如下代码:

@echo off



set RAR_CMD="C:\Program Files\WinRAR\WinRAR.exe"



set USERNAME=system



set PASSWORD=a123



set SIDDISCRIBE=HZPG



set CONDETION1=%USERNAME%/%PASSWORD%@%SIDDISCRIBE%



set DIRECTIONPATH=E:/db_backup



set FILENAME=oradata



set hour=%time:~,2%





if "%time:~,1%"==" " set hour=0%time:~1,1%



set TIMESTYLE=%date:~0,4%-%date:~5,2%-%date:~8,2%-%hour%-%time:~3,2%-%time:~6,2%



set FILEPATH=%DIRECTIONPATH%/%FILENAME%_%TIMESTYLE%.dmp



set LOGPATH=%DIRECTIONPATH%/%FILENAME%_%TIMESTYLE%.log



set RARPATH=%DIRECTIONPATH%/%FILENAME%_%TIMESTYLE%.rar



echo ============================================



echo 正在备份Oracle数据库,请稍等......



echo ============================================



exp userid=%CONDETION1% file=%FILEPATH% log=%LOGPATH%



echo 备份完成!



echo ============================================



echo 压缩备份文件,请稍等......



echo ============================================



%RAR_CMD% a -df "%RARPATH%" "%FILEPATH%" "%LOGPATH%"



echo 压缩完成!





echo ============================================



echo 正在计算压缩文件数量.....



set  f=rar



for /f %%i in ('dir /b /s /a-d *.%f% ^| find "." /c') do set s=%%i



echo %f% 文件数量有:%s%



if %s% equ 8 (



set p=e:/db_backup/

for /f %%i in ('dir %p% /a-d *.%f% ^/b /od /tc') do del %%i /a /f &goto x 

:x

echo 删除成功!

)

 

 

你可能感兴趣的:(oracle数据库)