The Arch way of syncing script


I like FreeFileSync, a syncing utility. There are several reasons for me to consider it is a good syncing utility,

  • Allows preview
  • Mirror, destination exactly as source
  • Update, update destination based on source, no deletion
  • Sync, allows propagate deletion, detects conflicts.
  • Delete to Trash can (or Recycle bin)
  • Multiple pairs of folders
  • Swap directions
  • Allows to edit the direction of specific files, or ignore the files.

All the bold features are which I prefer the most, especially the last one. That means, after the preview (or comparing), I can decide to change the direction of the files to be copied, left-to-right or right-to-left.

The next thing I like about FreeFileSync is the cross-platform. It is working on Windows and Linux. However, there is a drawback, it does not work in Mac OS X. Then, I look for other alternative syncing tools that work on Mac OS X with these features. None of them works as FreeFileSync.

The best among them is Synkron. However, the Synkron’s interface is not as intuitive as FreeFileSync. It uses multiple tabs for the syncing pairs. I cannot edit the syncing direction of specific files as FreeFileSync.

As a result, I tried to write a shell script to solve the syncing problem on Mac OS X. The script does not have all the features as FreeFileSync, but it provides an easier way for me to do the syncing. Since I like Arch Linux, I tried to use the Arch Linux way to write the script.

So, my shell script uses “rsync” for synchronisation. The script will read a configuration file, written in shell script form. The pairs of folders are written in an array form.

#example, sync.conf
pairs=("temp/" "temp2/" #first pair, always use variable called "pairs"
"foo/" "bar/") #next pair
# Always trailing with "/" for each directory, it is based on rsync

The script actually works with rsync for each pair of items in “pairs” array. To use the script,

./sync.sh -f sync.conf

Then, there are 2 prompts, first let you make sure the then pairs and the pairs and the synchronisation mode, update, mirror, or merge. Default mode is “mirror”.

The following is your synchronization setting:
temp/    =>     temp2/
foo/     =>     bar/
Mode: mirror
Confirm this setting? [y,n]

If “y” (yes), then the script will use rsync to do a dry-run (meaning without any changes), this is something like preview. Then, the second prompt asks for confirmation whether you want to continue. If “yes”, then start syncing.

One of the features I like over the script is the backup. The script will backup the deleted files into the folder “syncYYYYMMDD”. This is because I cannot use the Trash Can from command-line. So, I am using this script to sync in Mac OS X.

The script is available here.

Advertisements

2 thoughts on “The Arch way of syncing script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s