Using Unison to synchronize data on a USB stick

If graphical synchronization tools like Toucan are not flexible enough for your needs, you might want to try Unison, an easy-to-use yet powerful synchronization utility. To install Unison on your USB stick, download its command-line version (the unison-x.xx.x-win-text.exe file), rename the file to unison.exe, and move it into the root of the USB stick. Create a unison folder in the same location.

Although Unison is not designed to run from a removable disk, it will happily do so if you specify a couple of parameters. Since Unison is available as a command-line utility, you can write a simple batch script with all the necessary parameters and configuration options. Create a new text file and enter the following code, substituting the string that designates your own Firefox default directory:

@echo off
set unison=.\unison
set USB_Path=.\FirefoxPortable\Data\profile
set Local_Path=C:\Documents and Settings\User\Application Data\Mozilla\Firefox\Profiles\vmu5dry8.default
echo Ready to sync %Local_Path%
pause

unison "%USB_Path%" "%Local_Path%" -batch -log -logfile log.txt -times -prefer newer

echo All done! Details are in the log.txt file.
pause

The set unison command specifies the alternate unison folder in the root of the USB stick. This prevents Unison from storing data in the default location on the hard disk. The next two commands define the synchronization directories. Unfortunately, Unison can’t use relative paths, so you have to provide the exact paths to the folders and edit them manually later on, if needed. Finally, the unison command performs synchronization of the specified directories with the following parameters:

  • -batch performs synchronization without user interaction
  • -log -logfile log.txt enables logging and specifies a logfile
  • -times keeps the files’ modification times
  • -prefer newer resolves conflicts by keeping the newest file

Save the file with the .bat extension and put it in the root folder of the USB stick. Before you synchronize the Firefox profile, do a couple of dry runs on dummy directories (remember to edit the USB_Path and Local_Path values accordingly) to avoid any potential problems.

Using this batch file you can synchronize not only Firefox profiles, but all sorts of data. Unison's manual provides a comprehensive description of Unison’s features and options, which you can use to write more sophisticated scripts.

Related articles:

PageDateUserTags
Handy Linux backup scripts and commands 2007/09/20 11:14 Dmitri Popov , ,
Quick and easy FTP backup with lftp 2008/01/09 12:31 Dmitri Popov ,
Sync everything with Conduit 2008/06/18 00:01 Dmitri Popov , ,
Toucan: versatile portable backup utility 2007/08/06 15:28 Dmitri Popov , , ,
Using Unison to synchronize data on a USB stick 2007/08/09 12:32 Dmitri Popov , , ,

AddThis Social Bookmark Button

 
articles/usbunison.txt · Last modified: 2008/06/01 16:16 (external edit)
 
OpenOffice.org user? Read the Writer for Writers and Advanced Users book
GNU FDL OpenOffice.org Powered by DokuWiki