In part four of our series on working with Macrium Reflect, we look at using VBScript to handle a monthly backup cycle. I’ll show you how to generate a template VBScript source file and modify a couple of lines to enable selective execution of the XML definition files created in the previous tutorials.
So far we’ve created full and incremental image definitions and scheduled these to run in a weekly backup cycle. We’ve also used the disk space management option to ensure that our backup disk doesn’t overflow. But, what if you want to schedule your images using a monthly calendar cycle? Say you want to run a full image on the first Monday of every month and an incremental image for all other weekdays. How do you do that?
Macrium Reflect uses the standard Windows Scheduler to schedule all backups and images. This has the advantage of being a very well tried and tested scheduler, plus it reduces valuable program overhead by using an existing, running service. However, while the Windows Scheduler is great for repeating weekly pattern of days, it can’t handle monthly exclusions very well. In our above example we can schedule the full image to run on the first Monday of each month without a problem, but the incremental images would have to be scheduled for every weekday. This means that on the first Monday of each month you’d run both the full and incremental images. This isn’t a very elegant solution; so what do we do?
The answer is VBScript. With VBScript we have total flexibility to do anything we want. We can also reduce the number of tasks to schedule to just one.
If you’re unfamiliar with VBScript source, it can look rather daunting. The syntax seems unnecessarily complex and verbose. However, one thing to remember is that in most cases you can just copy existing code examples and modify them slightly to make them work for you. Macrium Reflect generates a great working template for you to modify, and I’ll show you a couple of simple code lines to add to achieve the scheduling scenario I’ve outlined above.
OK, let’s begin…
A quick summary of the functions used above:
The Date keyword is the current system date.
The Weekday function returns the day of the week as a number. 1 = Sunday, 2 = Monday etc.
DateAdd simply subtracts 7 days from the current date. The “d” means that we are subtracting (or adding) days. The other possibilities are, “yyyy” - Year, “q” – Quarter, “m” – Month, “y” - Day of year, “w” – Weekday, “ww” - Week of year, “h” – Hour, “n” – Minute, “s” – Second.
The Month function returns the month (1-12) of the DateAdd result and compares this with the current month using the ‘<>’ not equal to operator.
You’ve done it! VBScript code that modifies the running order of your images. VBScript gives you complete flexibility for any situation you can think of.
This is just a very small example of the power of VBScript. If you want to delve further into VBScript, have a look at the options in the generator. It generates separate functions for each option and provides some handy comments to help you understand the code. An excellent reference of VBScript functions can be found at http://www.w3schools.com/VBscript/vbscript_ref_functions.asp . Here you’ll find, not just the date functions introduced in this article, but every function available to you.
In the next tutorial we’ll imagine that the worst has happened and your PC has been infected with a killer virus. Windows won’t start! How do you get your system back? Don’t panic, I’ll reveal all.
For more information about Macrium Reflect visit http://www.macrium.com.
Could this be used to select a different destination if the default one is full? So e.g. the default could be "\\server\backups" and if that fails, try again on "\\server\backups2" (assuming the latter is on a separate partition), if that fails, try again on "\\server\backups3" etc. ?
Any chance you could support Python as scripting language?
How do you test the script for validity? E.g. in item 1 above, you would need to make Reflect believe that 1st and 2nd partitions are full to really test all branches. In Python, test stubs are easy to write: you would redefine the Backup() function to return true only on the third call, so you could have one line of code in the script that you set to either True or False to determine whether to rebind Backup() and you're in business! Is it equally easy in VBScript?