The Importance of Backups
Last Updated on Thursday, 17 June 2010 10:08 Written by admin Tuesday, 1 June 2010 10:16
The Importance of Backups
This may be teaching you to suck eggs but human nature being what it is, backing up your data is often put off, just like checking your pensions or reviewing your insurance – and it can be just as important.
I believe in two main principles with regard to backing up your computer:
1. Backups must be automated
2. Recovering backed-up data must be simple
These two principles lend themselves nicely to residential users; the more complicated your backup becomes, the more fragile it becomes.
The commercial market, on the other hand, generally requires complex “Grand-father, Father, Son” type backups, both long-term and short-term, with off-site storage and a host of other complications. Thus corporate backups often require a dedicated job function to manage them and discussion of this is perhaps for another time.
Here, I want to talk about designing a simple automated backup that will reliably make a copy of your critical data to another storage medium, be it a hard disk or memory stick.
Firstly you need to step back from the detail and ask yourself how upset you would be if your laptop or Desktop was stolen. Obviously the loss of the machine itself would be upsetting, but that aside, if the loss of the data on the machine sets you nerves jangling then read on.
In line with principle one above, the ideal backup must run frequently, unobtrusively and automatically. It must backup your chosen data, regardless of whether the files are currently in use, and it should give you some sort of indication that it is doing its job (or not as the case may be).
In line with principle two above, if disaster strikes, it should be a simple matter to access or restore your data. For example, a common disaster happens when, in a fit of absentmindedness, you save a new document using the same name as an existing one, overwriting the original document and losing hours of hard work. Usually when this is about to happen Windows will prompt you, warning you what will happen and asking you to click YES to continue or NO to cancel. This is where human frailty kicks in and just after you have clicked YES you get that horrible sinking feeling and then the frantic, unbelieving scrabble to try to locate the evaporated data…
The perfect backup would be an exact copy of your hard disk (this is often called an “Image” of the disk). Then when something goes wrong all you would need to do would be to restore the image.
In practice this is difficult to achieve for a number of reasons, not least being the many hours it would take to make and restore the backup – during which you would not be able to use the machine.
So the first of many compromises is necessary. You need to decide what to backup, or, more importantly what you don’t need to backup.
In the stolen machine scenario, you buy a brand new machine, which is unlikely to be exactly the same as your stolen machine. Now you need to be able to access your data quickly, preferably without the assistance of an expert-friend or consultant.
If your backup was written to an external hard drive or memory stick, it is very likely to be “USB” based. Therefore it’s almost certain that you will be able to use it with your new machine and simply access your data.
The fly in the ointment here is that while the new machine will be able to access your data, it may not have the necessary programs installed to make sense of it. For example if your data comprises Microsoft Word documents or Excel Spreadsheets then you will need to have Microsoft Office installed. If your data is music held in the popular iTunes Library then you will need Apple’s iTunes to be installed before you can listen to the music. The good news is that as long as you have access to the Internet, you can often download the necessary software. Failing that you, hopefully, will still have your original disks from when you bought the software.
Right, now how do you go about achieving the above?
You can purchase any number of backup programs some are good some are not. Some are complex some are useless.
I propose that you roll your own!
What follows is not for the feint hearted, but if you carefully follow the instructions you will be rewarded by a transparent backup fulfilling the above principles and have peace of mind.
Quick Start.
Apologies.
Goals.
System Requirements.
Acknowledgements.
Resources – (stuff you’ll need to download).
BACKUP.CMD.
NOTES:
Appendix 1 – An example of Backup.cmd with variables expanded.
Appendix 2 - Sample BackupList.txt file.
Appendix 3 - STRT.CMD.
Appendix 4 – The Code for BACKUP.CMD.
Appendix 5 – The Code for STRT.CMD.
Appendix 6 – Overview Diagram.
Quick Start
If you don’t want to read through all this stuff and just want to get your backup running then here is a quick start guide:-
- Create the folder C:\Backup
- Create a text file called Backup.cmd and copy & paste the Backup.cmd text into this file.
- Create a text file called strt.cmd and copy & paste the strt.cmd text into this file
- Create a text file called BackupList.txt and copy & paste the BackupList.txt text into this file.
- Google the Net for a torrent file called “Volume Shadow Versions” to get a collection of the relevant versions of vshadow.exe (plus Dosdev.exe & Robocopy.exe) and copy the files to C:\backup. Or, if you want to do it the hard way, refer to resources below where you can download and extract the versions from the relevant Microsoft Windows Software Development Kit (SDK) for your platform and locate vshadow.exe. You should find it in:-
C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\vsstools (for Win7-32-bit version)
C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\x64\vsstools (for Win7-64-bit version)
C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\vsstools (for Vista-32-bit version)
and copy it to C:\backup – (rename it appropriately – see note 9)
- Download the Windows Server 2003 Resource Kit Tools, locate robocopy.exe and copy it to C:\backup
- Download the Dosdev.exe and copy it to C:\backup
- Download the Hstart.exe and copy it to C:\backup
- Modify BackupList.txt to meet your backup requirements
- Modify the parameters in strt.cmd to meet your requirements
- Modify the vshadow.exe filename on line 23 of backup.cmd to meet your requirements
Apologies
I must apologise for the format of this document.
I originally created it in Word 2007 and but have had some difficulty copying it into Word Press and have had to make some compromises.
Goals
I needed a backup process that was simple, automated and invisible.
I have written at length, here, on my backup philosophy, so won’t rehash it again except to say that my goals were for a residential user to be able to backup:-
- to an external drive or memory stick
- frequently and automatically
- files that are currently in use
Additionally:
- It should be possible to use Windows Explorer to list the backup files/folders which should look the same as the originals so that recovering data is a simple drag and drop task
- The script should report the success or failure of each backup
- The script should produce detailed log files.
System Requirements
- Windows XP,Vista or 7 (32-bit or 64-bit)
- Vshadow.exe See below (Resources)
- Dosdev.exe Freeware by Olof Lagerkvist, http://www.ltr-data.se
- Robocopy.exe See below (Resources)
- Hstart.exe (optional)
- An external backup drive(preferably)
Acknowledgements
As you will see by my code and documentation I am not a professional programmer. I’m sure you can improve upon it and can find some glaring faults and omissions. Your comments would always be welcome – as long as they are polite! I must, however, acknowledge the original concept, written back on 5 Jan 2005, by Adi Oltean in his blog that I stumbled across here. I have based this script upon his original code. Thanks Adi.
Hidden start is a great utility to hide the command windows and enables you to set this script up to run from the task scheduler. Please see ntwind.com site for more info about this useful utility.
Robocopy is a hugely versatile, excellent utility – not least because of it’s ability to skip files that have already been copied. This alone speeds up the backup process impressively.
Microsoft’s Volume Shadow Service VShadow.exe is an essential component in this script as it solves one of the biggest problems – it facilitates backing up files that are in use. Without it it would not have been possible to automate the script.
Olof Lagerkvist’s Dosdev.exe utility is an excellent companion to VShadow.exe, enabling Robocopy to “talk” to the shadow volume created by VShadow.exe
Resources – (stuff you’ll need to download)
Google the Net for a torrent file called “Volume Shadow Versions” to get a collection of the relevant versions of vshadow.exe (plus Dosdev.exe & Robocopy.exe). If that fails then try sourcing the files from:
- Microsoft Windows Software Development Kit (SDK) Update for Windows Vista for VShadow.exe
- Microsoft Windows Software Development Kit (SDK) for Windows 7 for VShadow.exe
- Windows Server 2003 Resource Kit Tools for Robocopy.exe
- Softpedia:Home > Windows > System > System Miscellaneous > Dosdev for Dosdev
- Hidden Start for Hstart.exe
BACKUP.CMD
In order to make the code more readable I have hyperlinked most lines to a notes section below
- @echo off
- Echo **********************************************************
- Echo * *
- Echo * Backup is commencing. This may take up to 10 minutes *
- Echo * or more *
- Echo * (Depending on the amount of the data to be backed up) *
- Echo * *
- Echo * Please be patient *
- Echo * *
- Echo **********************************************************
- setlocal
- if NOT “%CALLBACK_SCRIPT%”==”" goto :IS_CALLBACK
- Set BKPDRV=%3
- :CheckForDrive
- if exist %BKPDRV%:\%BKPDRV%Drive.txt goto fileexists
- Echo **** The Backup Drive can’t be found *** >DriveNotFound.log
- EXIT 1
- :fileexists
- set SOURCE_DRIVE_LETTER=%1
- set SHADOW_DRIVE_LETTER=%2
- set CALLBACK_SCRIPT=%~dpnx0
- set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
- %SOURCE_DRIVE_LETTER%:\Backup\%4-vshadow.exe -script=%TEMP_GENERATED_SCRIPT% -exec=%CALLBACK_SCRIPT% %SOURCE_DRIVE_LETTER%: >vshadow.log
- if errorlevel 1 del /f %TEMP_GENERATED_SCRIPT% & exit 1
- del /f %TEMP_GENERATED_SCRIPT%
- @goto :EOF
- :IS_CALLBACK
- @echo on
- setlocal
- call %TEMP_GENERATED_SCRIPT%
- %~dp0dosdev.exe %SHADOW_DRIVE_LETTER%: %SHADOW_DEVICE_1%
- Echo Start: %date% %time% >%SOURCE_DRIVE_LETTER%:\Backup\Backuplog.log
- Echo Start: %date% %time% >%SOURCE_DRIVE_LETTER%:\Backup\RedirectedConsoleOutput.log
- FOR /F “eol=; tokens=1,2 delims=,” %%G IN (%SOURCE_DRIVE_LETTER%:\Backup\BackupList.txt) Do call :RunRoboCopy %%G %%H
- goto :closedosdev
- :RunRoboCopy
- Robocopy %SHADOW_DRIVE_LETTER%:%1 %BKPDRV%:\%2 /E /XJ /NP /LOG+:%SOURCE_DRIVE_LETTER%:\Backup\Backuplog.log >>%SOURCE_DRIVE_LETTER%:\Backup\RedirectedConsoleOutput.log
- if errorlevel 16 echo ***FATAL ERROR*** & exit %errorlevel%
- if errorlevel 8 echo **FAILED COPIES** & exit %errorlevel%
- if errorlevel 4 echo *MISMATCHES* & exit %errorlevel%
- goto :eof
- :closedosdev
- %~dp0dosdev.exe -r -d %SHADOW_DRIVE_LETTER%:
NOTES:
1. Parameters needed to run this batch file:
Running this script requires the following syntax:-
Backup.cmd %1 %2 %3 %4
E.G. “C:\Backup\Backup.cmd C B K SrvrW7x64″
%1 = C This is the Source Drive letter where the user’s data is stored – usually the “C” Drive. Note: I don’t include the “:”
%2 = B This is a temporary Drive letter for the Shadow Volume (see note 9 below)
%3 = K This is the Destination Drive letter where the backup data is stored – usually an external USB drive
%4 = SrvrW7x64 This is the prefix I have given for the VSS program specific to the user’s O/S. E.g. SrvrW7x64-vshadow.exe (see note 9)
These parameters are usually fed to this script from a startup script (C:\Backup\strt.cmd)or, more commonly, from the Task scheduler. See Appendix 1 for details on strt.cmd
2. Setlocal
Here, “setlocal” is used to make sure that any variables in this script will not remain defined after its execution is complete.
Be aware that because of the recursive nature of this script (it calls itself through one of the parameters of SrvrW7x64-vshadow.exe) close attention needs to be paid to the behaviour of parameters, variables and environment variables – some are not visible in subsequent recursions and therefore need to be explicitly defined with the SET command. See more below.
3. Recursion
Because this script needs to call itself (see above) a logic gate is needed to check if this is the first, or a subsequent iteration. (Certain actions need to be performed only on the first iteration). This is done by checking for the emptiness of the variable “%CALLBACK_SCRIPT%”. i.e. this variable is created on the first iteration, therefore if it is not set (or does not exist) then this must be the first iteration. The logic of this line of script is confusing because it is negatively phrased but what it is saying is: if the contents of the variable is not the same as an empty string, then jump to the subroutine. Another way to paraphrase this is: if the variable exists, then jump to the subroutine, or conversely, if the variable is empty/does not exist, then ignore the jump to the subroutine and continue execution normally.
4. Set BKPDRV
The Backup drive letter is supplied by the third parameter that instigates this script, (see note 1 above), but the recursive nature of this script means that the second time this script is run, (from within the SrvrW7x64-vshadow.exe line of code – see line 23) it is run without parameters and therefore the third parameter no longer exists. This problem is solved by “remembering” the third parameter during the first iteration by setting it as the %BKPDRV% variable, which will then be visible to subsequent iterations.
Before the backup begins we must verify that the backup drive is on-line. I do this by checking to see if the file “<drive letter>Drive.txt” (where <drive letter> is the drive letter specified by parameter %BKPDRV%) is visible. i.e. if you specify “K” as parameter %3 in C:\Backup\strt.cmd then this file will be “KDrive.txt”. The file is an empty text file.
If the file is not found then the script will abort and a message will be written out to the C:\Backup\DriveNotFound.log file. This is the most common cause of failure and can be easily detected by checking the time stamp of this file.
When SrvrW7x64-vshadow.exe calls this script (the 2nd iteration) it does so without parameters, therefore the parameters supplied by C:\Backup\strt.cmd need to be remembered – see note 4 above. Also note on line 21 the special parameter %~dpnx0% is used; this is simply the drive (d), path (p), name (n), and extension (x) of the currently running script (0). (See line 21 of Appendix 1)
SrvrW7x64-vshadow.exe creates a temporary device name, similar to “\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy35”. We can access this information via the -script=%TEMP_GENERATED_SCRIPT% parameter in line 23. This is a small script file that, when run, sets the device name as the variable: %SHADOW_DEVICE_1%. We can then feed this variable to the program dosdev.exe which associates it with the drive letter B:
9. Vshadow.exe
The purpose of this line is to enable us to backup files that would normally be in use and therefore not available for backup, like Outlook’s mailbox.pst. This is where the recursion happens. See the description of the –exec parameter below.
If you refer to line 23 in Appendix 1 you will see a version of this line with the variables replaced with values. This makes it much easier to read.
Here is a breakdown and explanation of each of the important elements in this line.
%SOURCE_DRIVE_LETTER% A single letter without the customary colon. E.g. “C”
: The drive letter’s colon.
\Backup\ The backup folder where all the scripts and logfiles are located e.g. “\Backup\”
%4 The forth parameter from C:\Backup\strt.cmd e.g. “SrvrW7x64”. Each platform has its own version of vshadow.exe (unfortunately they all have the same name)and it is essential that the correct one is in the C:\Backup folder. In this case the example script is to run on a Windows 7 64-bit system and therefore needs the specific version of vshadow.exe for this platform. I have prefixed each version to differentiate them . Below is the list of the versions:-
SrvrW7x64-vshadow.exe For Windows 7 64-bit
SrvrVista-vshadow.exe For Vista 32-bit
SrvrVista-vshadow.exe also for Win 7 32-bit (I think)
Vistax64-vshadow.exe For Vista 64-bit
XP-vshadow.exe For XP 32-bit
You might need to experiment with the above for other windows versions. Refer to this article I wrote about these versions.
-vshadow.exe The rest of the program name.
-script=%TEMP_GENERATED_SCRIPT% This is a parameter fed to vshadow.exe to get it to output a temporary script which looks like the following:-
SET SHADOW_SET_ID={e8d4d81c-337a-4df1-bda0-b7be96c5e0da}
SET SHADOW_ID_1={0b2fc776-3ebc-459c-9437-af02b4fbd46f}
SET SHADOW_DEVICE_1=\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy35
Of the above three lines, we are only interested in the third – %SHADOW_DEVICE_1% (see below notes 15 & 16)
-exec=%CALLBACK_SCRIPT% This is a parameter fed to vshadow.exe to get it to execute another script, while vshadow.exe is alive. This is important because vshadow.exe relinquishes the shadow copy when it finishes. So this is where the real work of this script is done. Also this is where the recursion happens as the script that this parameter calls is the same as the running script. Recursion here allows everything to be done from a single script. The second time this script is run is does something completely different because of the “if” statement on line 12 where it checks for the non-existence of the %CALLBACK_SCRIPT%. This time round it does exist, so the script jumps to :IS_CALLBACK where the robocopy routine is located.
%SOURCE_DRIVE_LETTER% This is the drive that vshadow.exe is to make a shadow copy of.
: The drive letter colon
>vshadow.log This is a redirection of the console output to log the activity of line 23 to C:\Backup\vshadow.log. The single “>” ensures that this log is overwritten each time this line is executed.
10. Error Traps
If vshadow.exe encounters an error it returns a non-zero errorlevel. Errors caught in lines 38, 39 & 40 cause vshadow.exe to abort. This sets a non-zero error level upon exiting vshadow.exe. Trapping this here enables the script to exit back to Hstart.exe with an errorlevel set to 1. Hstart will then interpret this as a failed backup and display an error message. Additionally, before exiting back to Hstart.exe, the script cleans up by deleting the temporary script.
11. Remove GeneratedVarsTempScript.cmd
This is a housekeeping line – it gets rid of the temporary script file that vshadow.exe created. See more at note 23 below
12. Finish
This is the last line of the script
This is the payload subroutine, where the script execution comes on the second iteration, jumping from the “if” statement on line 12. This is where the main work is done.
14. Setlocal2
Refer to note 2 above
Refer to the “-script” parameter discussed in note 9 above. This is where this script is executed in order to set the %SHADOW_DEVICE_1% parameter
16. Dosdev.exe
Dosdev.exe is a little utility that assigns a drive letter to a device. Using %SHADOW_DEVICE_1% – (see note 15) we are now able to assign the shadow copy device created by vshadow.exe to a drive letter; in this example “B:” Refer to note 7 for an explanation of the %~dp0 and Appendix 1 line 31 for an example
17. Echo on
I switch echo on here so that the console output can be recorded and logged.
I use the single “>” redirect character in lines 32 and 33. This ensures that a fresh log file is created each time these lines are executed.
19. BackupList.txt
Line 34 parses a text file. For simplicity’s and versatility’s sake I didn’t want to include the files/folders to be backed up within this script. Instead I wanted to list them in a separate simple text file. See Appendix 2 for an example of backuplist.txt. Each line of this file is made up of two parts separated by a comma. The first part being the name of the source folder and the second being the destination folder. Note also, that each part is enclosed in quotes. This is necessary to cater for multi-word file paths. Line 34 uses the “FOR /F … IN … DO” construct where “eol=;” specifies that the “;” character signifies a comment and the line is to be ignored, the “tokens=1,2” specifies the two parts to each line and “delims=,” specifies that the comma is the delimiter separating the two parts. Refer to this link for a clear explanation of the syntax for this construct. I specify %%G as the variable to contain the first part. It is not necessary to specify %%H for the second part as this is automatically implied by the “tokens 1,2” statement. After the DO statement it is necessary to call a subroutine; “:RunRoboCopy” with the two variables %%G & %%H as parameters to force their expansion because, for some strange reason, this does not happen as part of the FOR … DO construct.
20. RunRoboCopy
This is a subroutine that loops through each of the lines in backuplst.txt. Processing each line with the Robocopy routine specified on line 37. Again referring to line 37 in Appendix 1 will make it easier to understand this line.
Please also note carefully that the %1 and %2 referred to in this line refer to the parameters supplied in the call statement at the end of line 34 NOT the parameters supplied at the start of this script by C:\Backup\strt.cmd i.e. they refer to %%G & %%H which in turn refer to the two parts of each line read in from backuplst.txt.
The C:\Backup\Backuplog.log logfile is appended to by using “/LOG+:” Similarly the double “>>” is used to append to the C:\Backup\RedirectedConsoleOutput.log log file.
The other arguments:-
/E = Copies all subdirectories (including empty ones).
/XJ = Excludes Junction points.
/NP = Turns off copy progress indicator (% copied).
Robocopy uses 16 different errorlevel numbers to indicate the state of the backup. The script only deals with serious failures where data has not been backed up so only tests for Fatal Errors, Failed Copies and Mismatches.
16-Fatal Errors Serious error. Robocopy did not copy any files. This is either a usage error or an error due to insufficient access privileges on the source or destination directories.
8-Failed Copies Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further.
4-Mismatches This source directory corresponds to a destination file of the same name and cannot be processed. Housekeeping of the destination is recommended.
If any of these are detected I use the EXIT command.
NOTE: EXIT in this context causes the CALLBACK_SCRIPT to exit, returning control to the original instance of Backup.cmd and dropping us into error checking in line 24. As a result vshadow.exe aborts with its own errorlevel – (see note 10 above).
The “goto :eof” in line 41 does not end the entire script, instead it ends the “call :RunRoboCopy” subroutine and loops back to line 34 for the next line of input from backuplst.txt
23. Cleanup
Finally, after all the lines in backuplst.txt have been processed the drive letter associated with the shadow volume device can be deleted. Script execution then returns to line 25 where the temporary script is deleted and then onto line 26 where it finishes.
Appendix 1 – An example of Backup.cmd with variables expanded
This is a display of BACKUP.CMD with the variables replaced by values – this should make it easier to read
1. @echo off
2. Echo **********************************************************
3. Echo * *
4. Echo * Backup is commencing. This may take up to 10 minutes *
5. Echo * or more *
6. Echo * (Depending on the amount of the data to be backed up) *
7. Echo * *
8. Echo * Please be patient *
9. Echo * *
10. Echo **********************************************************
11. setlocal
12. if NOT "C:\Backup\Backup.cmd"=="" goto :IS_CALLBACK
13. Set BKPDRV=K
14. :CheckForDrive
15. if exist K:\KDrive.txt goto fileexists
16. Echo **** The Backup Drive can't be found *** >DriveNotFound.log
17. EXIT 1
18. :fileexists
19. set SOURCE_DRIVE_LETTER=C
20. set SHADOW_DRIVE_LETTER=B
21. set CALLBACK_SCRIPT=C:\Backup\test.cmd
22. set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
23. C:\Backup\SrvrW7x64-vshadow.exe -script=GeneratedVarsTempScript.cmd
-exec=C:\Backup\Backup.cmd C: >vshadow.log
24. if errorlevel 1 del /f GeneratedVarsTempScript.cmd & exit 1
25. del /f GeneratedVarsTempScript.cmd
26. @goto :EOF
27. :IS_CALLBACK
28. @echo on
29. setlocal
30. call GeneratedVarsTempScript.cmd
31. C:\Backup\dosdev.exe B:
32. echo Start: 15/05/2010 22:23:12.27 >C:\Backup\Backuplog.log
33. echo Start: 15/05/2010 22:23:12.27 >C:\Backup\RedirectedConsoleOutput.log
34. FOR /F " eol=; tokens=1,2 delims=," %G IN (C:\Backup\BackupList.txt) Do
call :RunRoboCopy %G %H
35. goto :closedosdev
36. :RunRoboCopy
37. Robocopy B:"\OutlookData" K:”\jbloggs\OutlookData” /E /XJ /NP
/LOG+:C:\Backup\Backuplog.log >>C:\Backup\RedirectedConsoleOutput.log
38. if errorlevel 16 echo ***FATAL ERROR*** & exit %errorlevel%
39. if errorlevel 8 echo **FAILED COPIES** & exit %errorlevel%
40. if errorlevel 4 echo *MISMATCHES* & exit %errorlevel%
41. goto :eof
42. :closedosdev
43. C:\Backup\dosdev.exe -r -d B:
Appendix 2 – Sample BackupList.txt file
;This is a comment line and is ignored by the script
"\Program Files (x86)\Intuit\QuickBooks Regular\Autobackup","\%username%\QuickBooks"
"%HOMEPATH%\AppData\Roaming\Mozilla\Firefox","\%username%\Firefox"
"%HOMEPATH%\AppData\Local\Microsoft\Windows Mail","\%username%\WinLiveMail"
"%HOMEPATH%\AppData\Roaming\Winamp\Plugins\Gracenote","\%username%\Gracenote"
"%HOMEPATH%\Documents","\%username%\Documents"
"%HOMEPATH%\Music","\%username%\Music"
"%HOMEPATH%\Videos","\%username%\Videos"
"%HOMEPATH%\Desktop","\%username%\Desktop"
"%HOMEPATH%\Pictures","\%username%\Pictures"
Appendix 3 – STRT.CMD
1. @echo off
2. echo *********************************************************************
3. echo * After you press any key, this window will close and your backup *
4. echo * will run in the background. *
5. echo * *
6. echo * Please be patient, the backup may take 10 minutes or longer *
7. echo * *
8. echo * NOTE *
9. echo * ==== *
10. echo * Please do not remove your memory stick *
11. echo * till you get a pop-up message saying: *
12. echo * *
13. echo * "Backup has completed successfully!" *
14. echo * *
15. echo * *
16. echo *********************************************************************
17. pause
18. REM This code can be cut and pasted into the Task Scheduler to automate backup
19. start C:\Backup\hstart.exe /NOCONSOLE /WAIT /D="C:\Backup\" /TITLE="Automated Backup" /MSG="Backup has completed successfully!" /ERRMSG="An error occurred while backing up data." ""C:\Backup\Backup.cmd" C B K SrvrW7x64"
NOTES:
I use HSTART.EXE (hidden Start) to run the whole backup process in the background so that the user is not disturbed with multiple command windows.
Hstart.exe examines the errorlevel state after backup.cmd has completed. If the state is non-zero then it returns an error, alerting the user to a backup problem, otherwise it returns a successful message.
Problems can be resolved by inspecting the following log files:
Backuplog.log
DriveNotFound.log
RedirectedConsoleOutput.log
vshadow.log
Appendix 4 – The Code for BACKUP.CMD
@echo off
Echo **********************************************************
Echo * *
Echo * Backup is commencing. This may take up to 10 minutes *
Echo * or more *
Echo * (Depending on the amount of the data to be backed up) *
Echo * *
Echo * Please be patient *
Echo * *
Echo **********************************************************
setlocal
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK
Set BKPDRV=%3
:CheckForDrive
if exist %BKPDRV%:\%BKPDRV%Drive.txt goto fileexists
Echo **** The Backup Drive can't be found *** >DriveNotFound.log
EXIT 1
:fileexists
set SOURCE_DRIVE_LETTER=%1
set SHADOW_DRIVE_LETTER=%2
set CALLBACK_SCRIPT=%~dpnx0
set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
%SOURCE_DRIVE_LETTER%:\Backup\%4-vshadow.exe -script=%TEMP_GENERATED_SCRIPT% -
exec=%CALLBACK_SCRIPT% %SOURCE_DRIVE_LETTER%: >vshadow.log
if errorlevel 1 del /f %TEMP_GENERATED_SCRIPT% & exit 1
del /f %TEMP_GENERATED_SCRIPT%
@goto :EOF
:IS_CALLBACK
@echo on
setlocal
call %TEMP_GENERATED_SCRIPT%
%~dp0dosdev.exe %SHADOW_DRIVE_LETTER%: %SHADOW_DEVICE_1%
Echo Start: %date% %time% >%SOURCE_DRIVE_LETTER%:\Backup\Backuplog.log
Echo Start: %date% %time% >%SOURCE_DRIVE_LETTER%:\Backup\RedirectedConsoleOutput.log
FOR /F "eol=; tokens=1,2 delims=," %%G IN (%SOURCE_DRIVE_LETTER%:\Backup\BackupList.txt) Do
call :RunRoboCopy %%G %%H
goto :closedosdev
:RunRoboCopy
Robocopy %SHADOW_DRIVE_LETTER%:%1 %BKPDRV%:\%2 /E /XJ /NP
/LOG+:%SOURCE_DRIVE_LETTER%:\Backup\Backuplog.log
>>%SOURCE_DRIVE_LETTER%:\Backup\RedirectedConsoleOutput.log
if errorlevel 16 echo ***FATAL ERROR*** & exit %errorlevel%
if errorlevel 8 echo **FAILED COPIES** & exit %errorlevel%
if errorlevel 4 echo *MISMATCHES* & exit %errorlevel%
goto :eof
:closedosdev
%~dp0dosdev.exe -r -d %SHADOW_DRIVE_LETTER%:
Appendix 5 – The Code for STRT.CMD
@echo off
echo *********************************************************************
echo * After you press any key, this window will close and your backup *
echo * will run in the background. *
echo * *
echo * Please be patient, the backup may take 10 minutes or longer *
echo * *
echo * NOTE *
echo * ==== *
echo * Please do not remove your memory stick *
echo * till you get a pop-up message saying: *
echo * *
echo * "Backup has completed successfully!" *
echo * *
echo * *
echo *********************************************************************
pause
REM This code can be cut and pasted into the Task Scheduler to automate backup
start C:\Backup\hstart.exe /NOCONSOLE /WAIT /D="C:\Backup\" /TITLE="Automated Backup"
/MSG="Backup has completed successfully!" /ERRMSG="An error occurred while backing up
data." ""C:\Backup\Backup.cmd" C B K SrvrW7x64"
Appendix 6 – Overview Diagram

Awesome tip thanks!
File backups don’t have to be a chore. A reasonable backup plan will go for ages