Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have been using Windows Server Backup on a Windows 2008 R2 server for quite a while now to create nightly bare metal backups to a network drive in case of drive failure. The nightly backup overwrites itself each night.

Unfortunately bad sectors began appearing on my system drive. This allowed the nightly backup to be created WITH bad sectors and thus destroying any possibility of restoration. It also overwrote the previous backup, thus making the whole backup process worthless!

Am I using WSB as it was intended to be used? How do I circumvent the potential for overwriting backups with a faulty one that cannot be restored?????

Is it possible to make a batch script that validates the integrity of a backup and then offloads it if true? What would such a script look like?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I wrote a batch file that starts at 4am, which is guaranteed to be after all my backups are finished.

It RARs all the folders inside WindowsImageBackup (or whatever that folder is called), gives them a date stamped filename, and copies them to a secondary server, and from there they are replicated off-site.

This way I've got months (years?) worth of historical backups, at least one of which will be good.

As for not overwriting backups, the only way WSB allows you to do this is to use a locally mounted block-storage device (such as a hard drive, USB drive or an iSCSI disk).

As for validating the image, I have another script that runs Sunday evening at the remote site that grabs a random backup image from the last 7 days, un-RAR's it, creates a VM and boots it. Because I haven't quite finished the scripting part, every Monday morning (when I remember) I spend 5 minutes just initiating the restore procedure and then check it later to see if it succeeded.

All in all it sounds a bit ghetto, but this particular client had a very limited budget (read: none), so I was restricted to using free tools. And so far it's worked really well.


To enable WBS at GPO level, and schedule a complete backup every night

@echo off

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /f %%I IN (
 'wmic volume get driveletter'
) DO (
  ECHO %%I | FIND ":"
  IF ERRORLEVEL 1 (
   echo Failed: %%I
  ) ELSE (
   ECHO %%I | FIND "D:"
   IF ERRORLEVEL 1 (
     IF NOT [!_TEMPVAR!]==[] SET _TEMPVAR=!_TEMPVAR!,
     SET _TEMPVAR=!_TEMPVAR!%%I
    ) ELSE (
      echo Skipping CD-ROM
    )
  )

)

wbadmin enable backup -addtarget:\\enetsbackup1\Backups -schedule:23:00 -systemState -allCritical -vssFull -user:backupservice@enets.local -password:[password] -quiet -include:!_TEMPVAR!

To RAR files into date-stamped and passworded files (run on the server that hosts all the backup file shares)

@ECHO OFF

SET _WINRAR=C:\Program Files\WinRAR\Rar.exe
SET _BACKUPPATH=C:\QNAPBackups\WindowsImageBackup\

REM RAR All backups into date-named files

forfiles -p %_BACKUPPATH% -m *.rar -d -3 -c "cmd /c del @path"

FOR /D %%I IN (%_BACKUPPATH%*) DO (
    "%_WINRAR%" a -ag-YYYYMMDD -ep1 -hp[password] -m2 -df  "%%I.rar" "%%I"
)

Move files into off-site sync dir, and clean up the sync dir

prepareoffsite.bat

SET _BACKUPPATH=C:\QNAPBackups\WindowsImageBackup\

forfiles -p %_BACKUPPATH% -m *.rar -c "cmd /c C:\Batches\CopyOffsite.bat @path"

copyoffsite.bat

A little bit of an explanation:The batch takes the backup name and it goes through a list of txt files, and in each txt file it has a list of all the names of the machines. Depending on which file the machine name is in, it goes into a different folder (as some are synced nightly, others weekly, depending on how important they are).

@ECHO OFF

SET _OFFSITEDIR=C:\QNAPBackups\Offsite\

FOR /f "tokens=1 delims=- " %%a in ("%1") DO (
  FOR /f "tokens=4 delims=\ " %%b in ("%%a") DO (
    FIND /C /I "%%b" C:\Batches\OFFSITE-DB.txt | find ": 1" 1>nul && GOTO Offsite_Database
    FIND /C /I "%%b" C:\Batches\OFFSITE-TS.txt | find ": 1" 1>nul && GOTO Offsite_Terminal
    FIND /C /I "%%b" C:\Batches\OFFSITE-EX.txt | find ": 1" 1>nul && GOTO Offsite_Exchange
    FIND /C /I "%%b" C:\Batches\OFFSITE-A1.txt | find ": 1" 1>nul && GOTO Offsite_AllInOne
    FIND /C /I "%%b" C:\Batches\OFFSITE-MS.txt | find ": 1" 1>nul && GOTO Offsite_Miscella

   GOTO :NotFound
  )
)

:Offsite_Database
MOVE /Y %1 %_OFFSITEDIR%Databases\
GOTO EOF

:Offsite_Terminal
MOVE /Y %1 %_OFFSITEDIR%TerminalServers\
GOTO EOF

:Offsite_Exchange
MOVE /Y %1 %_OFFSITEDIR%Exchange\
GOTO EOF

:Offsite_AllInOne
MOVE /Y %1 %_OFFSITEDIR%AllInOne\
GOTO EOF

:Offsite_Miscella
MOVE /Y %1 %_OFFSITEDIR%Misc\
GOTO EOF

:NotFound
ECHO %1 >> C:\Batches\OFFSITE-NotFound.txt
GOTO EOF

:EOF

forfiles -p %_OFFSITEDIR%Databases\ -m *.rar -d -3 -c "cmd /c del @path"
forfiles -p %_OFFSITEDIR%TerminalServers\ -m *.rar -d -3 -c "cmd /c del @path"
forfiles -p %_OFFSITEDIR%Exchange\ -m *.rar -d -3 -c "cmd /c del @path"
forfiles -p %_OFFSITEDIR%AllInOne\ -m *.rar -d -3 -c "cmd /c del @path"
forfiles -p %_OFFSITEDIR%Misc\ -m *.rar -d -3 -c "cmd /c del @path"
share|improve this answer
    
Care to share your scripts? –  John Gardeniers Dec 28 '11 at 22:58
1  
@JohnGardeniers - there you go –  Mark Henderson Dec 29 '11 at 1:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.