{"id":1303,"date":"2013-06-12T22:55:21","date_gmt":"2013-06-12T22:55:21","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=1303"},"modified":"2013-06-12T22:55:21","modified_gmt":"2013-06-12T22:55:21","slug":"how-to-create-a-data-backup-tool-with-synctoy-vb-script","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=1303","title":{"rendered":"How To Create A Data Backup Tool With SyncToy &#038; VB Script"},"content":{"rendered":"<p>In this article, I\u2019m going to show you how you can use a combination of Microsoft\u2019s free SyncToy tool with a very simple scheduled VB Script that will automate the entire data backup process.<\/p>\n<h2>Setting Up SyncToy For Automated File Backups<\/h2>\n<p>Microsoft SyncToy is a free tool that lets you \u201cpair\u201d up folders for either an echo clone or full synchronization. I\u2019ll explain the difference below. However, the point here is that before you can automate the directory and file backups, you need to set up all of the areas you want to copy and where you want the archived copy to go.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"data backup\" src=\"http:\/\/main.makeuseoflimited.netdna-cdn.com\/wp-content\/uploads\/2011\/12\/synctoy1.png\" width=\"443\" height=\"388\" \/><\/p>\n<p>You do this when you first run the SyncToy by clicking on \u201c<em>Create New Folder Pair<\/em>\u201d and then defining the left (from) folder, and the right (to) folder. The second step of the sync setup process is to choose the type of synchronization you want.<\/p>\n<p>\u201c<em>Synchronize<\/em>\u201d is a two-way data backup. This means if any new file appears or is updated on the left or the right, those changes will be copied over to the other directory. On the other hand, Echo just mirrors all changes from the left directory onto the right. This is usually what people want to do when they\u2019re backing up a particular directory \u2013 they want all changes mirrored on the backup.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"data backup system\" src=\"http:\/\/main.makeuseoflimited.netdna-cdn.com\/wp-content\/uploads\/2011\/12\/synctoy2.png\" width=\"443\" height=\"388\" \/><\/p>\n<p>In the scheduled solution that I\u2019m going to show you how to set up, I\u2019m going to set up four folder pairs. Each pair is a backup that I want to handle during one particular time of the day. In the morning, I\u2019m going to back up one folder. At noon, I will back up another, and so on.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"data backup system\" src=\"http:\/\/main.makeuseoflimited.netdna-cdn.com\/wp-content\/uploads\/2011\/12\/synctoy3.png\" width=\"580\" height=\"329\" \/><\/p>\n<p>Once you have all of the folders set up that you want to perform automated backups for, it\u2019s time to set up the script that will launch SyncToy using the command line feature that Microsoft offers with the tool.<\/p>\n<h2>Setting Up The SyncToy Automation Script<\/h2>\n<p>The VB Script that I\u2019m 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.<\/p>\n<p>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 \u201cdatabackup.wsf\u201d.<\/p>\n<pre>&lt;job&gt;<\/pre>\n<pre>&lt;script language=\"VBScript\"&gt;<\/pre>\n<pre>Option Explicit<\/pre>\n<pre>On Error Resume Next<\/pre>\n<pre>Dim HourNow<\/pre>\n<pre>Dim strHour<\/pre>\n<pre>Dim WshShell<\/pre>\n<pre>Dim strProgFiles<\/pre>\n<pre>HourNow = Hour(Now())<\/pre>\n<pre>set WshShell=CreateObject(\"WScript.Shell\")<\/pre>\n<pre>strProgFiles = WshShell.ExpandEnvironmentStrings(\"%PROGRAMFILES%\")<\/pre>\n<pre>Select Case HourNow<\/pre>\n<pre> case HourNow &gt;= 0 and HourNow &lt; 7<\/pre>\n<pre> WshShell.exec strProgFiles &amp; \"\\SyncToy 2.1\\SyncToyCmd.exe -R MorningFiles\"<\/pre>\n<pre> case HourNow &gt;= 7 and HourNow &lt; 13<\/pre>\n<pre> WshShell.exec strProgFiles &amp; \"\\SyncToy 2.1\\SyncToyCmd.exe -R NoonFiles\"<\/pre>\n<pre> case HourNow &gt;= 13 and HourNow &lt; 19<\/pre>\n<pre> WshShell.exec strProgFiles &amp; \"\\SyncToy 2.1\\SyncToyCmd.exe -R MailArchives\"<\/pre>\n<pre> case else<\/pre>\n<pre> WshShell.exec strProgFiles &amp; \"\\SyncToy 2.1\\SyncToyCmd.exe -R EveningFiles\"<\/pre>\n<pre>End Select<\/pre>\n<pre>WScript.Quit<\/pre>\n<pre>&lt;\/script&gt;<\/pre>\n<pre>&lt;\/job&gt;<\/pre>\n<p>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 \u201cMorningFiles\u201d pair that you set up. Between 7 a.m. and 12:59, the \u201cNoonFiles\u201d pair, and so on.<\/p>\n<p>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 \u201c<em>Create Task\u201d<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"data backup system\" src=\"http:\/\/main.makeuseoflimited.netdna-cdn.com\/wp-content\/uploads\/2011\/12\/synctoy4.png\" width=\"455\" height=\"391\" \/><\/p>\n<p>Name the task, and then click on the trigger tab. Make sure to select \u201c<em>On a schedule<\/em>\u201c, <em>Daily, recur every day, start at 3 a.m<\/em>., 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.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"backup data\" src=\"http:\/\/main.makeuseoflimited.netdna-cdn.com\/wp-content\/uploads\/2011\/12\/synctoy5.png\" width=\"527\" height=\"413\" \/><\/p>\n<p>Those are all within one of the four time spans that you scheduled into your script. Now click on the <em>Actions<\/em> tab, and select \u201c<em>Start a program<\/em>\u201d from the dropdown list and browse to where you stored the script.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"backup data\" src=\"http:\/\/main.makeuseoflimited.netdna-cdn.com\/wp-content\/uploads\/2011\/12\/synctoy6.png\" width=\"468\" height=\"258\" \/><\/p>\n<p>That\u2019s 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 \u201c<em>SyncToyCmd.exe -R EveningFiles<\/em>\u201d \u2013 with whatever file pair you named after \u201c-R\u201d.<\/p>\n<p>You can monitor whether your script is running by checking the SyncToy log file at \u201c<em>C:\\Users\\Owner\\AppData\\Local\\Microsoft\\SyncToy\\2.0\\SyncToyLog.log<\/em>\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"data backup\" src=\"http:\/\/main.makeuseoflimited.netdna-cdn.com\/wp-content\/uploads\/2011\/12\/synctoy7.png\" width=\"579\" height=\"354\" \/><\/p>\n<p>The log updates every time SyncToy is run, and it\u2019ll show you what directory was backed up, when it was done, the file count and the size of the backup.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, I\u2019m going to show you how you can use a combination of Microsoft\u2019s free SyncToy tool with a very simple scheduled VB Script that will automate the entire data backup process. Setting Up SyncToy For Automated File Backups Microsoft SyncToy is a free tool that lets you \u201cpair\u201d up folders for either [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1303","post","type-post","status-publish","format-standard","hentry","category-computer-tech-stuff"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/1303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1303"}],"version-history":[{"count":2,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/1303\/revisions"}],"predecessor-version":[{"id":1305,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/1303\/revisions\/1305"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}