Setting Up The SyncToy Automation Script

Setting Up The SyncToy Automation Script

The VB Script that I’m going to show you will check the current time of day, and will run the appropriate command to launch the Microsoft SyncToy program and back up the right directory.

It does this by using the name of the paired directory that you set up in the tool above. Copy the script into notepad and save it as something like “databackup.wsf”.

<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.1SyncToyCmd.exe -R MorningFiles"
 case HourNow >= 7 and HourNow < 13
 WshShell.exec strProgFiles & "SyncToy 2.1SyncToyCmd.exe -R NoonFiles"
 case HourNow >= 13 and HourNow < 19
 WshShell.exec strProgFiles & "SyncToy 2.1SyncToyCmd.exe -R MailArchives"
 case else
 WshShell.exec strProgFiles & "SyncToy 2.1SyncToyCmd.exe -R EveningFiles"
End Select

The script above simply checks the hour right now (based on the PC clock where the script runs), and if it is between midnight and 6:59 a.m., it will sync the “MorningFiles” pair that you set up. Between 7 a.m. and 12:59, the “NoonFiles” pair, and so on.

All you have to do now is set up a Windows scheduled task that will launch the script above four times a day within the four time spans. This is also pretty easy, just go to the Control Panel, Administrative Tools, and open up the Task Scheduler. Click on “Create Task”.

data backup system

Name the task, and then click on the trigger tab. Make sure to select “On a schedule“, Daily, recur every day, start at 3 a.m., and then at the bottom click to repeat the task every 6 hours. This will trigger the task at 0300, 0900, 1500 and 2100 hours.

backup data

Those are all within one of the four time spans that you scheduled into your script. Now click on the Actions tab, and select “Start a program” from the dropdown list and browse to where you stored the script.

backup data

That’s all there is to it! Now, the task scheduler will launch your single script four times a day (no need to mess with multiple tasks). Your script will handle launching SyncToy in command mode by launching “SyncToyCmd.exe -R EveningFiles” – with whatever file pair you named after “-R”.

You can monitor whether your script is running by checking the SyncToy log file at “C:UsersOwnerAppDataLocalMicrosoftSyncToy2.0SyncToyLog.log

data backup

The log updates every time SyncToy is run, and it’ll show you what directory was backed up, when it was done, the file count and the size of the backup.

Does this data backup solution work for you? Do you have any other ways you like to automatically back up important data files and folders? Share your thoughts in the comments section below.

Categories: SyncToyBookmark

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>