Archive for the ‘ Backups ’ Category

Basically just a follow up here. I wanted to use the script in Part 1, with some backup hardware and Windows Scheduler to automate this task.

I wanted to use something that was easy to swap media out and had a large capacity. With the price of hard drives these days, it seemed reasonable that I use something that used a standard SATA internal hard drive. After some research, I decided upon a

NexStar Hard Drive Dock

image

I picked one up for under $40 and with a 1TB SATA drive, it seemed like a great addition to my backup solution.

Windows Scheduler

Now we need some way to kick of the script. To set the script from the previous post to run automatically on a schedule, I used a utility found in Windows called “Windows Scheduler” You can find this tool under Control Panel. Here’s a picture of what it looks like with this job already setup:

WindowsScheduler

As you can see the job is named “Network Backup” and setup to run once every day at 7:17 PM. I set it up like this since I was unsure of when or if the computers being backed up would be turned on and available or not. I figured there was a pretty good chance that at least once a week, it would get lucky and backup the files on each computer. If you read the previous post, you’ll remember that I only created new backup folders for each week of the month. This will cause the backup files to be placed in the same folder for one week, and then switch to the next folder the following week. That way, I’ll be have the option to go back at least 4 weeks to get a copy of some file or set of files.

Here’s how Windows Scheduler looks with this job setup:

backup2

And here is the same window but viewing the schedule information:

Backup3

With a standard hard drive in the dock, here’s what it looks like:

NexStar_Hard_Drive_Dock2

With the external SATA (eSATA) cable hooked up, this can write files as fast as my 100mb network can feed it.

For the last few days, this system has been in place and appears to be working as expected.

I almost forgot…The first time this job runs, it takes QUITE A WHILE, since the first backup in each week’s folder must copy all the files. Obviously all subsequent backups simply grab new or recently modified files and the job runs for a much shorter duration.

Leave your Comment

hard-drive1 One thing I promised myself was at some point (early on) I would create an automated backup solution for my home computers. I wanted an automated and easy to configure system that I was confident of backing up my most important files. The criteria for this operation were the following:

  • Must use a well known and free backup command-line tool that I could script out exactly how and what I wanted it to do

  • Must be capable of being run from a scripting language (preferably VBScript).

  • Should be able to copy both large files and large quantities of files that might crash less robust tools

  • Have the ability to copy from Windows’ default hidden shares like “C$\” and UNC paths like “\\Foo”

A friend of mine had mentioned a long-time windows utility called Robocopy (he also provided some of the VBScript that I used). This command line tool was designed by Microsoft for reliable mirroring of directories and directory trees. You can check out the wikipedia article for Robocopy if you are so inclined.

Robocopy meets all of the requirements mentioned above.

After setting up the computers on the workgroup with the required permissions and settings, the next step was to create a script file that would for now, manually backup files (I’ll cover an automated solution as well as a database configuration and logging solution in future articles).

I wanted to have a process that would eventually create multiple copies of all the files required for backup. There would be a separate copy of each file for each week of the month. This means I would only get a fresh backup of files once every week. For the types of stuff I wanted to backup (family pictures, music and movie files, code and design files) I felt this was adequate. When viewing the backup destination, I would see a maximum of 6 folders (since there could be 6 different weeks in a month) with names like Week1, Week2, Week3, etc. The directories and files would all be inside these folders. Here’s a copy of what that backup destination structure could look like:

For a script and Robocopy to do this, it should have the following steps:

  • Setup of global parameters including a collection of machine\directory paths for configuration

  • A process of adding the path information to the destination area including machine name and share name

  • From a script, Robocopy will only be provided one source and one destination at a time so there will be a primary loop in the script that loops through all specified source paths

  • A process to capture and write the results from the process so it may be reviewed at a later date.

  • Functions to determine the week of the month, attempt to create the week folder, and create a name for the results file

  • A method of executing the Robocopy tool with the proper commands and capturing the information it provides while executing. This is the key to the whole process!

Robocopy requires a command set like the following example:

“Robocopy \\foo\c$\documents D:\Backups\Week1 /S /NP /R:2 /W:5”

This will tell Robocopy to attempt to connect to the hidden share “c$”  on machine “foo”, and copy everything under the directory “documents”  to the backup destination “d:\Backups\Week1”. The stuff behind the destination are known as switches. The “/S” copies all subdirectories unless they are empty. The “/NP” tells Robocopy to not provide any progress information while copying files. The “/R” is tells the tool to retry 2 times before giving up when there is an error. Finally, the “/W” provides the time to wait before retrying, in this case 5 seconds. There are many other switches, but I’ll leave it to you to research all the unique ways Robocopy can be manipulated.

I won’t go into all of the code, but here is a chunk of code for specifying what source paths there are:

Dim array_Sources(3) ‘Source Paths Array
Dim array_Destinations(3) ‘Destination Paths Array

array_Sources(1)    = “\\octavious\e$\Sierra”
array_Sources(2)    = “\\spartan\c$\logs\”
array_Sources(3)    = “\\Minimac\Lisa\”

As you can see one of the machines is a Mac Mini, which with SMB and the proper account settings, can be backed up as well.

Here’s the key to the whole VBScript and Robocopy marriage to get this system to work:

Set oWSH = WScript.CreateObject(”WScript.Shell”)
Set oCOMMAND = oWSH.Exec(sCommand)

Where sCommand is basically a string containing the Robocopy command line for that specific source and destination set as shown above.

Here’s a copy of the entire VBScript backup solution file.

You can probably find a copy of Robocopy somewhere on Microsoft’s site if you dig around a little.

There’s also a GUI for Robocopy that someone at Microsoft built along with all the files and documentation.

Next I’ll be looking at providing some hardware to this solution so I can easily switch out my backup media with another. Remember, this is only the first step in the overall solution…Eventually we’ll have a database tied to this so we can dynamically assign backup sources and log backup metrics for reporting and monitoring of the backup process.

Comments (1)