@ECHO OFF
TITLE TestDirector8.1 数据备份程序Ver1.0   今天是: %date:~0,16%

COLOR 0A
ECHO     ========================================================================
ECHO     =  Application Name: TestDirector8.1 Data Auto Backup                  =
ECHO     =  Author: xiaobin                                                     =
ECHO     =  Create Date: 2007.6.7                                               =
ECHO     =  Last Modify Date: 2007.6.21                                         =
ECHO     =  Company: Beijing ZhongSou Online Software CO., LTD                  =
ECHO     ========================================================================

SET /A TS=%TIME:~0,2%*3600+%TIME:~3,2%*60+%TIME:~6,2%

REM *****************************************************************************
REM 设置日期变量 格式:xxxx-xx-xx [可修改]
SET Dates=%date:~0,4%%date:~5,2%%date:~8,2%

REM 设置时间变量 格式:xx.xx.xx [可修改]
SET Tsp="%time:~0,1%"
IF %Tsp%==" " (SET Times=0%time:~1,1%%time:~3,2%%time:~6,2%) & GOTO LS
SET Times=%time:~0,2%%time:~3,2%%time:~6,2%

:LS
REM 设置源文件夹变量[可修改]
SET SourceDir=F:TD8_DIR

REM 设置目的文件夹变量[可修改]
SET DestDir=E:TD_Backupdata

REM 设置日志文件夹变量[可修改]
SET LogsDir=E:TD_Backuplogs

REM 参数拼接[不能修改]
SET DDir=%DestDir%TD8_Dir_%Dates%_%Times%
SET LDir=%LogsDir%%Dates%_%Times%.log
SET Tpe=%DestDir%tmp.txt
SET Tpe1=%LogsDir%tmp.txt
REM SET Tpe2=%LogsDir%tmp1.txt
SET Tmp=%LogsDir%tmp_%Dates%_%Times%_s.txt
SET Tmp1=%LogsDir%tmp_%Dates%_%Times%_d.txt

REM 日志文件保留数[可修改]
SET H=5

REM 备份目录保留数[可修改]
SET S=5

REM 设置提示信息环境变量
SET Msg00=正在运行,请耐心等待……
SET Msg01=源文件夹[ %SourceDir% ]不存在!!!
SET Msg02=目的文件夹[ %DestDir% ]不存在!!!
SET Msg03=日志文件夹[ %LogsDir% ]不存在!!!
SET Msg04=程序已终止运行……
SET Msg10=成功拷贝文件
SET Msg11=未找到拷贝文件
SET Msg12=用户通过ctrl-c中止拷贝操作
SET Msg13=预置错误阻止文件拷贝操作
SET Msg14=拷贝过程中写盘错误
SET Msg20=30秒钟之后,自动关闭窗口!!!

REM *****************************************************************************
REM 判断目录是否存在,如果不存在直接退出

IF EXIST %SourceDir% GOTO Loop1
SET COMM_Msg=%Msg01%
GOTO EXT

:Loop1
IF EXIST %DestDir% GOTO Loop2
SET COMM_Msg=%Msg02%
GOTO EXT

:Loop2
IF EXIST %LogsDir% GOTO BEGIN
SET COMM_Msg=%Msg03%

:EXT
ECHO     %COMM_Msg%
ECHO     %Msg04%
GOTO EXT1

REM *****************************************************************************

:BEGIN
ECHO     %Msg00%

IF EXIST %LDir% DEL /Q %LDir%

ECHO. >> %LDir%
ECHO   TestDirector8.1 数据备份日志文件             Author:xiaobin  >> %LDir%
ECHO ============================================================================  >> %LDir%
ECHO 开始日期: %date% >> %LDir%
ECHO 开始时间: %time:~0,8% >> %LDir%
SET /A TS=%TIME:~0,2%*3600+%TIME:~3,2%*60+%TIME:~6,2%
ECHO 源 目 录: %SourceDir% >> %LDir%
ECHO 备份目录: %DestDir% >> %LDir%
ECHO 日志目录: %LogsDir% >> %LDir%
ECHO ============================================================================  >> %LDir%

IF EXIST %DDir%  GOTO CPY0

REM 目录不存在则创建新目录
MKDIR %DDir%
ECHO 创建新目录[ %DDir% ]成功!!! >> %LDir%
GOTO CPY1

:CPY0
ECHO 目录[ %DDir% ]已经存在,将覆盖目录中的文件!!! >> %LDir%
:CPY1
ECHO ============================================================================  >> %LDir%
DIR /S /B /O-N /A:-D %SourceDir% > %Tmp1%

REM 备份开始
XCOPY /E /C /Y /H %SourceDir%*.*  %DDir% >> %LDir%

IF ERRORLEVEL 4 GOTO XCM4
IF ERRORLEVEL 3 GOTO XCM3
IF ERRORLEVEL 2 GOTO XCM2
IF ERRORLEVEL 1 GOTO XCM1
IF ERRORLEVEL 0 GOTO XCM0

REM *****************************************************************************
:XCM4
SET COMM_Msg=%Msg14%
GOTO END

:XCM3
SET COMM_Msg=%Msg13%
GOTO END

:XCM2
SET COMM_Msg=%Msg12%
GOTO END

:XCM1
SET COMM_Msg=%Msg11%
GOTO END

:XCM0
SET COMM_Msg=%Msg10%
GOTO END

REM *****************************************************************************

:END
ECHO     %COMM_Msg%
ECHO %COMM_Msg% >> %LDir%
ECHO. >> %LDir%

DIR /S /B /O-N /A:-D %DDir% > %Tmp%

REM 对比源目录与目的目录的文件数是否一致
SET U=0
FOR /F %%a IN (%Tmp%) DO @SET /A U+=1

SET T=0
FOR /F %%a IN (%Tmp1%) DO @SET /A T+=1

ECHO 文件数目比较…… >> %LDir%
ECHO   1.源目录[ %SourceDir% ]下的文件数为 %T% 个; >> %LDir%
ECHO   2.备份目录[ %DDir% ]下的文件数为 %U% 个! >> %LDir%
IF %T% NEQ %U% (ECHO 备份后的文件数与源目录中的文件数不相等,可能文件备份不全… >> %LDir%) ELSE (ECHO 备份后的文件数与源目录中的文件数相等,备份成功… >> %LDir% & ((IF EXIST %Tmp% DEL /Q %Tmp%) & (IF EXIST %Tmp1% DEL /Q %Tmp1%)))

ECHO. >>%LDir%
DIR /B /A:D /O-N %DestDir% > %Tpe%
DIR /S /B /O-N %LogsDir%*.log > %Tpe1%
REM DIR /S /B /O:-D /A:-D %LogsDir%tmp_*.txt > %Tpe2%

SET I=0
FOR /F "skip=%H%" %%a IN (%Tpe%) DO @IF EXIST %DestDir%%%a SET /A I+=1

REM 删除临时文件
REM SET /A P=%H%*2
REM FOR /F "skip=%P%" %%a IN (%Tpe2%) DO @IF EXIST %%a DEL /Q %%a

IF %I% GTR 0 GOTO DELBup
GOTO EXT1

:DELBup
ECHO 发现 %I% 个比较旧的备份目录,将自动删除它!! >>%LDir%
ECHO ………………………………………………………………….. >>%LDir%
FOR /F "skip=%H%" %%a IN (%Tpe%) DO @IF EXIST %DestDir%%%a ECHO %DestDir%%%a >>%LDir%
FOR /F "skip=%H%" %%a IN (%Tpe%) DO RMDIR /S /Q  %DestDir%%%a
FOR /F "skip=%S%" %%a IN (%Tpe1%) DO DEL /Q  %%a
ECHO ………………………………………………………………….. >>%LDir%
ECHO 删除旧的备份目录成功!! >>%LDir%
ECHO. >>%LDir%

REM *****************************************************************************

:EXT1
IF EXIST %Tpe% DEL /Q %Tpe%
IF EXIST %Tpe1% DEL /Q %Tpe1%

SET /A TS1=%TIME:~0,2%*3600+%TIME:~3,2%*60+%TIME:~6,2%
SET /A TSM=%TS1%-%TS%

ECHO ============================================================================  >> %LDir%
ECHO 结束时间: %time:~0,8% 总耗时: %TSM% 秒>> %LDir%
ECHO ============================================================================  >> %LDir%
ECHO.
ECHO     %Msg20%
PING -n 30 127.0.0.1 >NUL

EXIT

TD8.1 数据备份程序下载: 75



无觅相关文章插件,快速提升流量

Comments

There are no comments.

Leave a Reply

You must be logged in to post a comment.

传奇 似水流年 绽放 风筝 八月照相馆