Publish folders to web site after batch backup of folders and files


First, back up all folders and files under “D: \ project 1” under “C: \ website” to “D: \ backup 2012-9-1-52647”, and then publish “D: \ project 1” to “C: \ website”.
Backupandpublish.bat “D: \ project 1”

Copy codeThe code is as follows:
@echo off
set SourceDir=%1
set now=%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%%time:~3,2%%time:~6,2%
:: parameters
Set destdir = “C: \ website”
Set backdir = “D: \ backup% now%”
Echo is backing up
call:Backup %SourceDir% %DestDir% %BackDir%
Echo is publishing
call:Publish %SourceDir% %DestDir%
goto :eof
:: main program
setlocal enabledelayedexpansion
set SourceDir=%~1
set DestDir=%~2
set BackDir=%~3
:: calculate source path length
set SourceDirLen=0
set SourceDirStr=%SourceDir%
if not “%SourceDirStr%”==”” (
set /a SourceDirLen+=1
set “SourceDirStr=%SourceDirStr:~1%”
goto :next1
:: Backup
for /r “%SourceDir%” %%i in (*.*) do (
set BackPath=%%~dpi
set BackPath=%BackDir%!BackPath:~%SourceDirLen%!
set DestPath=%%i
set DestPath=%DestDir%!DestPath:~%SourceDirLen%!
set BackFilePath=%%i
set BackFilePath=%BackDir%!BackFilePath:~%SourceDirLen%!
echo !DestPath!
xcopy “!DestPath!” “!BackPath!” /r /y >nul 2>nul
If not exist “! Backfilepath!” (echo backup copy failed)
for /r “%SourceDir%” %%i in (\) do (
set SourcePath=%%i
set SourcePath=!SourcePath:~0,-1!
set BackPath=%BackDir%!SourcePath:~%SourceDirLen%!
md “!BackPath!” >nul 2>nul
setlocal disabledelayedexpansion
goto :eof
:: issue
set SourceDir=%1
set DestDir=%2
xcopy %SourceDir% %DestDir% /r /y /i /e
goto :eof