Automatically backup thumb drive in Windows XP

Although the conficker virus made malicious use of the Autorun properties of thumb drives, this feature can be used for good!  Here’s how to use it to automatically synchronize directories and files on a USB thumb drive to a directory on your hard drive.

Software you’ll need:

We’ll use a Window’s batch script that will handle setting up the executing environment and launching.  Save the backupthumb.txt script to your USB disk, rename to backupthumb.cmd and tweak to your own needs.  By default the script will log everything to the logs directory on your USB disk.  See the rsync man page for all of the options available to you.

Next create the file that will tell rsync what files and directory to backup.  Just place the path to each file or directory on a separate line.  Using my script, the path is relative to the root of the USB disk and could look like:

data/accounts.kdb
docs/

Note the trailing slash which is important. Without it the files inside docs would NOT be backed up.  Also by default, rsync will not process the named paths in a recursive manner.  If you want it to, add –recursive as an argument to the rsync command in the script.

The next step is to create the autorun.inf file in the root of the USB disk with at least the following:

[autorun]
action=Backup Thumb Drive
open=binbackupthumb.cmd

The open parameter’s value is relative to the root of the thumb drive.  Here I assume you saved the script to the bin directory on your USB disk.  Please note that I had issues if I prefixed it with a slash.  You can also pimp out the USB disk’s display in My Computer by adding a few more parameters to the autorun.inf file:

icon=datacruzer.ico
label=Thumb Drive
shellbkup=Backup Thumb Drive
shellbkupcommand=binbackupthumb.cmd

This will use the cruzer.ico and label it Thumb Drive instead of the defaults.    It also adds a shell extension labeled “Backup Thumb Drive” which will execute our batch script when selected.  Handy to force a backup manually.  For the icon I just googled for cruzer icons and used ConvertICO.com to convert the PNG to ICO format.  If you’re like me and are lazy, you can just download the complete autorun.inf file.

If you stop at this point you will have an option in the Autoplay menu to “Backup Your Thumb Drive” when you insert your USB disk.  However our goal is to have it automatically perform the backup.  For this we need to use TweakUI to add a custom AutoPlay handler to launch our script.  Launch TweakUI and click on My Computer > AutoPlay > Handlers.  Click on the Create button.  For <description> type Backup Thumb Drive.  For <program name> type my backup script.  Then click on the Change Program… button and browse to the batch script.  Delete everything in the Args text box.  You can also set a custom icon to make it complete.  Again just use google to find something appropriate.

Then in My Computer, right click on your USB disk and select Properties.  On the AutoPlay tab, select Mixed content from the drop-down option box.  Change the action to Select an action to perform, and select our new Backup Thumb Drive option.  Lastly click the OK button.

And there you have it.  A nice and automatic backup method for your USB thumb drives.  Next up will be to show you how to replicate this in Linux.

Fri Oct 9 2009 | The Geek Life | Comments
Tags: ,,,,,
Related Posts: Windows 7 Powersaving

One Response to “Automatically backup thumb drive in Windows XP”

  1. 1 chris 9 October 2009 @ 1:44 pm

    Forgot to mention that this does not work in Windows 7RC and will probably not work in the final release. Because of the conficker virus, MS decided to yank the AutoRun capabilities for removable disk drives. Until I find a way to automate it on insertion, you’re left having to manually run the script.

Leave a Reply

  1.  
  2.  
  3.  

Navigation

Categories

Link Blog

Sites of Interest

Meta