window db2数据库备份Bat脚本

@echo off
REM Create by fengzhanhai on 2010.12.23 Used by backup database db2
REM ---tasks: 每天晚上24点运行
REM 计划任务命令参照格式:"C:\Program Files\IBM\SQLLIB\BIN\db2cmd.exe" "F:\db2-backup-bbs\script\dbbackup.bat"
REM ---环境配置-------------
set Backup_Log=F:\db2-backup-bbs\script\db2back.log
REM ---DBlist.txt最后需要增加一个回车,需要备份的数据库清单
set DBList=F:\db2-backup-bbs\script\dblist.txt
set User=db2admin
set Pwd=db2admin
set TargetPath=F:\db2-backup-bbs\
::获取日期 将格式设置为:20110820
set datevar=%date:~0,4%%date:~5,2%%date:~8,2%
::获取时间中的小时 将格式设置为:24小时制
set timevar=%time:~0,2%
if /i %timevar% LSS 10 (
set timevar=0%time:~1,1%
)
::获取时间中的分、秒 将格式设置为:3220 ,表示 32分20秒
set timevar=%timevar%%time:~3,2%%time:~6,2%
set FilePath=%datevar%%timevar%
set FilePath=123456789
set CMDHeader=db2 backup db
set CMDTail=user %User% using %Pwd% online to
REM rar.exe绿色压缩软件程序包需要的朋友可以将附件的rar.txt内容下载后改成后缀为exe的文件
set ProgramRar=%~dp0\rar.exe
REM 设置set db2clp=DB20FADE,设置db2clp的值为这个值就可以不需要新建窗口,运行db2命令了
REM  打开另外一个db2cmd的窗口,运行set db2clp,就会显示db2clp的值  记住这个值,就可以在任何已经存在的cmd窗口中
set db2clp=DB20FADE
REM ---检查数据库配置文件------
if not exist %DBList% (
echo %date% %time% %DBList% not found >> %Backup_Log%
exit
)
REM ---创建当日文件夹------
if not exist %TargetPath%%FilePath% (
md %TargetPath%%FilePath% > nul
echo %date% %time% create %TargetPath%%FilePath% folder >> %Backup_Log%
) else (
echo %date% %time% %TargetPath%%FilePath% exist >> %Backup_Log%
)
REM ---备份数据-------------
for /f "tokens=*" %%j in (%DBList%) do (
%CMDHeader% %%j %CMDTail% %TargetPath%%FilePath% >> %Backup_Log%
echo %date% %time% %%j backup done >> %Backup_Log%
)
REM ---压缩数据-------------
%ProgramRar% a %TargetPath%%FilePath% %TargetPath%%FilePath% > nul
echo %date% %time% compress  %TargetPath%%FilePath% done >> %Backup_Log%
REM ---删除压缩前数据-------------
RD /Q /S %TargetPath%%FilePath%
echo %date% %time%  delete %TargetPath%%FilePath% done >> %Backup_Log%
exit

你可能感兴趣的:(window)