First, under the "C:\ Web site" corresponding "D:\ Project 1" Under All folders and files back to the "D:\ backup 2012-9-1-52647", and then "D:\ Project 1" published to the "C:\ site."
usage:
Backupandpublish.bat "D:\ Project 1"
Copy Code code 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%
:: Parameter
Set destdir= "C:\ Web Site"
Set backdir= "D:\ backup%now%"
Echo.
Echo is backing up
Call:backup%sourcedir%%destdir%%backdir%
Echo.
Echo is releasing
Call:publish%sourcedir%%destdir%
Goto:eof
:: Main Program
: Backup
Setlocal enabledelayedexpansion
Set Sourcedir=%~1
Set destdir=%~2
Set Backdir=%~3
:: Calculating Source path length
Set sourcedirlen=0
Set sourcedirstr=%sourcedir%
: Next1
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 replication 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
:: Publish
:P ublish
Set sourcedir=%1
Set destdir=%2
xcopy%sourcedir%%destdir%/r/y/i/e
Goto:eof