LOGO

Create Data Backup Tool with SyncToy & VB Script

December 15, 2011
Create Data Backup Tool with SyncToy & VB Script

Automating Data Backups with SyncToy and VBScript

Previously, an article detailed various methods for creating complete system backups or images for Windows 7 computers. While comprehensive system backups are crucial, more frequent backups of critical directories and files are often necessary.

This is particularly relevant in IT environments where clients accumulate data in designated folders and require consistent, potentially daily or even hourly, data protection.

MakeUseOf (MUO) has previously explored numerous data backup options. These include articles by Tina on hard drive cloning, Stefan on file synchronization tools, and Shankar on PC-to-USB drive file syncing.

Justin recently published a piece on Redo Backup and Recovery. Each of these solutions offers valuable functionality.

However, organizations with concerns regarding free, third-party software, or those preferring exclusively Microsoft products, may encounter limitations in finding a suitable backup solution.

Leveraging Microsoft Tools for Reliable Backups

This article will demonstrate how to utilize Microsoft's free SyncToy tool in conjunction with a straightforward, scheduled VB Script to fully automate the data backup procedure.

This approach provides a secure and reliable method for safeguarding important data without relying on external software packages.

The combination of SyncToy and a VBScript allows for a customized backup schedule tailored to specific needs, ensuring data is consistently protected.

By employing native Microsoft tools, businesses can maintain control and security over their backup processes.

Automated File Backups with Microsoft SyncToy: A Setup Guide

Microsoft SyncToy is a complimentary utility enabling the creation of folder pairs for either echo cloning or complete synchronization. The distinction between these methods will be clarified shortly. However, the primary objective is to configure all desired copy sources and destination locations before automating the file backup process.

Initial configuration is performed upon the first execution of SyncToy by selecting "Create New Folder Pair". This involves specifying both the source (left) folder and the destination (right) folder.

Understanding Synchronization Options

The subsequent step in the setup process is selecting the appropriate synchronization method. "Synchronize" facilitates bidirectional data backup. Any new or modified files in either the source or destination folder will be replicated to the other. Conversely, Echo mode solely mirrors changes originating from the source directory to the destination.

Echo mode is generally preferred for backup purposes, ensuring that all alterations are reflected in the backup location. This provides a reliable mirrored copy of the original data.

For the automated scheduling solution detailed below, four folder pairs will be established. Each pair represents a distinct backup operation to be executed at a specific time of day.

Backups will be staggered throughout the day: one folder in the morning, another at noon, and so forth. This approach allows for granular control over the backup schedule.

set-automated-data-recovery-synctoy-vb-script-3.jpg

Automating Backups with Scripting

After defining all folders for automated backups, the next step involves creating a script to launch SyncToy via its command-line interface. Microsoft provides this functionality as part of the tool.

This scripting approach allows for fully automated, hands-free backups, ensuring data protection without manual intervention. The command-line feature offers flexibility and control over the backup process.

Automating SyncToy with a Script

This guide details a VBScript designed to automate the execution of Microsoft SyncToy, initiating backups based on the current time of day. The script intelligently launches SyncToy and backs up designated directories.

To begin, copy the script provided below into Notepad and save it with a ".wsf" extension, such as "databackup.wsf".

<job>

<script language="VBScript">

Option Explicit

On Error Resume Next

Dim HourNow

Dim strHour

Dim WshShell

Dim strProgFiles

HourNow = Hour(Now())

Set WshShell = CreateObject("WScript.Shell")

strProgFiles = WshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")

Select Case HourNow

 Case HourNow >= 0 And HourNow < 7 

 WshShell.Exec strProgFiles & "\SyncToy 2.1\SyncToyCmd.exe -R MorningFiles"

 Case HourNow >= 7 And HourNow < 13 

 WshShell.Exec strProgFiles & "\SyncToy 2.1\SyncToyCmd.exe -R NoonFiles"

 Case HourNow >= 13 And HourNow < 19 

 WshShell.Exec strProgFiles & "\SyncToy 2.1\SyncToyCmd.exe -R MailArchives"

 Case Else 

 WshShell.Exec strProgFiles & "\SyncToy 2.1\SyncToyCmd.exe -R EveningFiles"

End Select

WScript.Quit 

</script>

</job>

The script functions by determining the current hour and executing the corresponding SyncToy command for the appropriate directory pair, as previously defined within the SyncToy application.

Next, a Windows Scheduled Task must be created to launch this script four times daily, covering the designated time intervals. Access the Task Scheduler through the Control Panel, under Administrative Tools, and select "Create Task".

set-automated-data-recovery-synctoy-vb-script-4.jpg

Provide a name for the task, then navigate to the "Triggers" tab. Configure the schedule to run "Daily", recurring every day, starting at 3:00 a.m. Enable task repetition every 6 hours.

set-automated-data-recovery-synctoy-vb-script-5.jpg

These repetition intervals align with the time spans programmed into your script. Proceed to the "Actions" tab and select "Start a program" from the dropdown menu. Browse to the location where you saved the script.

set-automated-data-recovery-synctoy-vb-script-6.jpg

With these steps completed, the automation is configured. The Task Scheduler will now launch the script four times each day, and the script will manage the execution of SyncToy in command-line mode, utilizing commands like "SyncToyCmd.exe -R EveningFiles" – referencing the file pair name following the "-R" parameter.

The success of the script's execution can be verified by reviewing the SyncToy log file located at "C:\Users\Owner\AppData\Local\Microsoft\SyncToy\2.0\SyncToyLog.log".

set-automated-data-recovery-synctoy-vb-script-7.jpg

This log file is updated with each SyncToy run, detailing the backed-up directory, completion time, file count, and backup size.

Is this automated backup method suitable for your needs? We invite you to share any alternative data backup strategies you employ in the comments below.

Image Credit: Shutterstock

#SyncToy#VB Script#data backup#file synchronization#automation#scripting