Hi, I'm hoping someone can tell me if i'm on the right track. I'm trying to write a batch file to run as a task on a pc server running Win7 to back up our network drive to 5 external HDDs (Mon-Fri) which will be swapped out to match the day. Each HDD would have 4 folders (weeks). On the first cycle, I'd like the batch file to copy to week1, then week2 on the next cycle, then week3, then week4. Could someone decipher this batch file I've written or suggest perhaps an easier way to achieve my task? Thank you.
ECHO OFF
REM Edit e:\week4
set CAT=e:\week4
dir "%%CAT%%"/s/b/a | sort /r >> %week4%\files2del.txt
for /f "delims=;" %%D in (%week4%\files2del.txt) do (del /f/s/q "%%D" & rd /s/q "%%D")
del /f/s/q %week4%\files2del.txt
@ECHO OFF
SETLOCAL
SET _source=e:\week3
SET _dest=e:\week4
SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
ROBOCOPY %_source% %_dest% %_what% %_options%
ECHO OFF
REM Edit e:\week3
set CAT=e:\week3
dir "%%CAT%%"/s/b/a | sort /r >> %week3%\files2del.txt
for /f "delims=;" %%D in (%week3%\files2del.txt) do (del /f/s/q "%%D" & rd /s/q "%%D")
del /f/s/q %week3%\files2del.txt
@ECHO OFF
SETLOCAL
SET _source=e:\week2
SET _dest=e:\week3
SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
ROBOCOPY %_source% %_dest% %_what% %_options%
ECHO OFF
REM Edit e:\week2
set CAT=e:\week2
dir "%%CAT%%"/s/b/a | sort /r >> %week2%\files2del.txt
for /f "delims=;" %%D in (%week2%\files2del.txt) do (del /f/s/q "%%D" & rd /s/q "%%D")
del /f/s/q %week2%\files2del.txt
@ECHO OFF
SETLOCAL
SET _source=e:\week1
SET _dest=e:\week2
SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
ROBOCOPY %_source% %_dest% %_what% %_options%
ECHO OFF
REM Edit e:\week1
set CAT=e:\week1
dir "%%CAT%%"/s/b/a | sort /r >> %week1%\files2del.txt
for /f "delims=;" %%D in (%week1%\files2del.txt) do (del /f/s/q "%%D" & rd /s/q "%%D")
del /f/s/q %week1%\files2del.txt
@ECHO OFF
SETLOCAL
SET _source=\\ccfile\users
SET _dest=e:\week1
SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
ROBOCOPY %_source% %_dest% %_what% %_options%
batch file to backup network drive
Moderator: DosItHelp
Re: batch file to backup network drive
Leo wrote:Hi, I'm hoping someone can tell me if i'm on the right track. I'm trying to write a batch file to run as a task on a pc server running Win7 to back up our network drive to 5 external HDDs (Mon-Fri) which will be swapped out to match the day. Each HDD would have 4 folders (weeks). On the first cycle, I'd like the batch file to copy to week1, then week2 on the next cycle, then week3, then week4. Could someone decipher this batch file I've written or suggest perhaps an easier way to achieve my task? Thank you.
Maybe keeping a set of folders with the date as the folder name, would make it easier to determine which backup is which,
and the code for renaming the oldest backup folder to the current date is simple, when creating a new backup.
Wmic makes it simple to create a reliable date/time format string.