本帖最后由 ptsdy 于 2012-10-12 12:40 编辑
- @echo off
- set e=%date%
- set f=%e:~,10%
- set f=%f:/=-%
- set g=%f:-=%
- set h=%g:~3,1%
- set t=%time:~,8%
- set s=%t::=.%
- set wb=%~n0info.txt
- if not exist "%wb%" (echo Dir------To---------Dir>"%wb%"
- echo Source ^| Destination>>"%wb%")
- :backupinfo
- for %%k in ("%wb%") do ( cls & rem echo %%~zk
- if %%~zk leq 50 (echo Please input backup information and save !!!
- start /wait "" "%~dp0%wb%" & goto :backupinfo) )
- rem set Mapping source netpath=%wb:~,1%
- rem set Mapping source localpath =%wb:~1,1%
- set pan1=%wb:~,1%:
- set pan2=%wb:~1,1%:
- :echo "%pan1%" "%pan2%" &pause
- set netuser=
- set netpwd=
- if defined netuser (
- set netpwd="%netpwd%"
- set netuser=/user:"%netuser%")
- subst %pan2% /d 2>nul >nul
- net use %pan1% /del /y 2>nul >nul
- echo Please choice:
- echo 1:(common backup,fast,a few file not updated)
- echo 2:(detail backup, slowly, all files checked)
- set /p choice=choice:
- del /f /s /q "%~dp0log %f% %s%.txt" >nul 2>nul
- echo Start Time: %date:~,10% %time:~,8% >>"%~dp0log %f% %s%.txt"
- echo ---------------------------------- >>"%~dp0log %f% %s%.txt"
- set num=0
- setlocal enabledelayedexpansion
- for /f "eol=# skip=2 tokens=1,2 delims=|" %%i in ('type "%~dp0%wb%"') do (
- if "%%j" equ "" echo Error:Not defined destination path>>"%~dp0log %f% %s%.txt" & exit /b
- if "%h%" neq "2" goto :eof
- for %%q in ("%%i") do (set m=%%~q
- set n=!m:~,1!
- if "!n!" neq "\" (cd /d %windir%\system32
- subst %pan2% "%%i" 2>nul >nul || subst %pan2% "%%i\"
- if "!errorlevel!" neq "0" echo Error:Map localpath falure>>"%~dp0log %f% %s%.txt" & exit /b
- if "%choice%" equ "1" (call :main10 %pan2% "%%i" "%%j") else call :main20 %pan2% "%%i" "%%j"
- cd /d "%~dp0" & subst %pan2% /d 2>nul >nul
- ) else (net use %pan1% "%%i" %netpwd% %netuser%
- if "!errorlevel!" neq "0" echo Error:Map netpath falure>>"%~dp0log %f% %s%.txt" &exit /b
- if "%choice%" equ "1" (call :main10 %pan1% "%%i" "%%j") else call :main20 %pan1% "%%i" "%%j"
- cd /d "%~dp0" & net use %pan1% /del /y 2>nul >nul
- )
- )
- )
- echo Total backup files number: %num% >>"%~dp0log %f% %s%.txt"
- echo End Time: %date:~,10% %time:~,8% >>"%~dp0log %f% %s%.txt"
- start /wait "" "%~dp0log %f% %s%.txt"
- echo Save backup information and logs ??? n(not save) OR otherkey(save)
- set /p save=Whether save ? :
- if "%save%" equ "n" del /f /q "%~dp0log %f% *.txt" "%~dp0%wb%"
- endlocal & pause & exit /b
- ::.....................................................................
- :main10
- set "num1=0" & cd /d "%~dp0"
- echo [%time:~,8%] Common Backup:"%~2|%~3" >>"%~dp0log %f% %s%.txt"
- cd /d "%~1" && for /f "delims=" %%m in ('dir /a-d /s /b /od') do (
- if not exist "%%j%%~pm%%~nxm" (
- xcopy /y /s /e /c /g /h "%%m" "%%j%%~pm" && set /a num+=1 && set /a num1+=1
- )
- )
- echo [%time:~,8%] Backup files number: %num1% >>"%~dp0log %f% %s%.txt"
- echo ***********************************************************************>>"%~dp0log %f% %s%.txt"
- goto :eof
- ::.....................................................................
- :main20
- set num2=0
- set "change=0" & cd /d "%~dp0"
- echo [%time:~,8%] Detail Backup:"%~2|%~3" >>"%~dp0log %f% %s%.txt"
- cd /d "%~1" && for /f "delims=" %%m in ('dir /a-d /s /b /o-d') do (
- if not exist "%%j%%~pm%%~nxm" (
- xcopy /y /s /e /c /g /h "%%m" "%%j%%~pm" && set /a num+=1 && set /a num2+=1
- ) else (for %%n in ("%%j%%~pm%%~nxm") do (
- if "%%~zn" neq "%%~zm" (set "tm=%%~tm" & set "tm=!tm::=.!" & set "tm=!tm: =-!" & set "tm=!tm:/=-!"
- echo ●CHANGED #######%%i%%~pm%%~nxm>>"%~dp0log %f% %s%.txt"
- if not exist "%%j%%~pm%%~nm-C!tm!%%~xm" echo f | xcopy /y /s /e /c /g /h "%%m" "%%j%%~pm%%~nm-C!tm!%%~xm" && set /a num+=1 &&set /a num2+=1 && set /a change+=1)
- )
- )
- )
- echo Copy changed number: %change% >>"%~dp0log %f% %s%.txt"
- echo [%time:~,8%] Backup files number: %num2% >>"%~dp0log %f% %s%.txt"
- echo ***********************************************************************>>"%~dp0log %f% %s%.txt"
- goto :eof
- :backupinfo.txt (this bat's name front two must be letters and not exist repeat letter disk!)
- :##### Left | source path ; Right | destination path (Dont' have space)
- :##### [Dir--Dir] For example: \\192.168.1.5\a\b\c|d:\m\n ; example: y:|d:
复制代码
|