troubleshooting Question

Batch file for backups

Avatar of dan_computerx
dan_computerx asked on
Microsoft DOSWindows Server 2003Shell Scripting
22 Comments1 Solution414 ViewsLast Modified:

I am trying to adapt an old script that ran backups of an ADP database to run backups of a fingerprint database.  The old server was Server 2000; the new server is Server 2003 R2.

The script should do the following steps:

Rename a series of directories in a backup location
      Directory1 -> Directory2
      Directory2 -> Directory3
      Delete the oldest directory
Stop a named service
Copy a directory from production to a backup location
Start the named service
Mirror the backup location to a remote server

You end up with a series of directories as follows:


And a mirror on a second server.  It worked very well for years.

I'm having trouble getting the batch to run now.  I suspect that the Num2 variable isn't getting set, but I'm not sure.  Frankly I'm not very good with scripting :-(

Would you fix this for me?  You need RoboCopy installed for it to work.




REM - Make sure you have RoboCopy installed.  It is part
REM - of the Server Tools and I am calling it from the default
REM - location.

REM - Set the variables for renaming, path, and number of backups
REM - And make sure they are only set for the system
Set BackupPath=C:\backups\M2Sys
Set FolderName=BioPlugin
Set CopyFrom="C:\Program Files\BioPlugin"
Set CopyTo=C:\backups\M2Sys\BioPlugin.1
Set MirrorLoc=\\arad\h$\Ariel\M2Sys\BioPlugin
Set BackupLog=C:\backups\M2SysBackupLog.txt
Set ServiceLog=%BackupPath%M2SysServices.log
Set Services="M2SYS Fingerprint Server"
Set Num=5

REM - For each Backup, do the Rename Subroutine, which either  
REM - renames the folder, or deletes it if it is the last one.

For /L %%a in (%Num%,-1,1) Do Call :REN %%a

REM - Call the service stop subroutine.  The CALL command waits for 
REM - the referenced batch file to complete before continuing.

For %%b in (%Services%) Do Call :STOPSERVICES %%b

REM - Copy then entire BioPlugin directory to the C:\Backups\M2Sys\BioPlugin

"C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" %CopyFrom%  %CopyTo%  /COPYALL /MIR /SEC /R:2 /W:10 /LOG+:%BackupLog%  /NFL /NDL

REM - Call the service start batch file

For %%c in (%Services%) Do Call :STARTSERVICES %%c

REM - Mirror the entire %BackupPath% to your preferred server.

"C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" %BackupPath%  %MirrorLoc%  /COPYALL /MIR /ZB /SEC /R:2 /W:300 /LOG+:%BackupLog%  /NFL /NDL

REM - If Folder.Num exists, Set a Num2 variable to the next number
IF EXIST "%BackupPath%%FolderName%.%*" SET/A Num2=%*+1

REM - For Testing
ECHO "%Num2%"

REM - or kick out of the loop
IF NOT EXIST "%BackupPath%%FolderName%.%*" GoTo :EOF

REM - If this is the anything but the last folder, Rename the 
REM - folder from Pathname\FolderName.[Num..1] to Pathname\FolderName.Num2 
REM - And display exactly what we are doing
IF NOT %*==%Num% REN "%BackupPath%%FolderName%.%*" "%FolderName%.%Num2%"

REM - For Testing

REM - If this is the last folder, Delete the folder
REM - And display exactly what we are doing 

IF %*==%Num% RMDIR /S /Q "%BackupPath%%FolderName%.%*"
GoTo :EoF

REM - Set the logfile path
REM - Write the current date and time to the logfile
>> "%ServiceLog%" ECHO %DATE%%TIME%:
REM - Start the service, and write all output
REM - From the command to the logfile
>> "%ServiceLog%" 2>&1  NET START %*
GoTo :EoF

REM - Write the current date and time to the logfile
>> "%ServiceLog%" ECHO %DATE%%TIME%:
REM - Start the service, and write all output
REM - From the command to the logfile
>> "%ServiceLog%" 2>&1  NET STOP %*
GoTo :EoF

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 22 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros