Semi-automatic offline synchronization of a digital media player

When writing this post, I initially titled it “I ♥ rsync”. And I really, really do. Through the magic of rsync and a couple of scripts for Nautilus, I now have more-or-less automated synchronization of my Rockbox-equipped media player.
And it’s so easy, you can do it on your own in a few simple steps
h3. How it works
My solution works by adding a few nautilus scripts that do two things:
# Create symbolic links in a (predefined) directory, so you can sync this folder with the mp3 player. This is achieved through selecting files and folders for synchronization in Nautilus, and using a context menu script to create the actual links.
# Perform the actual synchronization. Also done with a simple context-menu Nautilus script (that _can_ be run from a shell, if wanted).
h3. Prerequisites
The first prerequisite here is actually that you have _some_ familiarity with the shell, and that you have a _backup_ of the important files on your media player. I have not devised this way of synchronization for the feeble of mind, or the ones with no backup, or able to restore their device, should this method leave it unusable. See the warning at the end of this post.
The first thing you need to do is to download the “create_symbolic_links”:http://g-scripts.sourceforge.net/nautilus-scripts/File%20System%20Management/create_symbolic_links
nautilus script from the “G-Script”:http://g-scripts.sourceforge.net/cat-filesysmgt.php repository, and save it to the @.gnome2/nautilus-scripts@ folder. From a shell, you can do it this way:
bc. $ wget -nv -O ~/.gnome2/nautilus-scripts/create_symbolic_links http://g-scripts.sourceforge.net/nautilus-scripts/File%20System%20Management/create_symbolic_links
Next, you need to create a directory into where you want to sync. I have called mine “rockbox”
bc. $ mkdir ~/rockbox
Further, we now need to slightly modify the script we downloaded, so that it syncs in to the correct directory:
bc. $ sed -i “/\/Desktop/rockbox” ~/.gnome2/nautilus-scripts/create_symbolic_links
Now, we need to make the script executable:
bc. $ chmod +x ~/.gnome2/nautilus-scripts/create_symbolic_links
h4. Installing zenity
The symbolic links script requires “Zenity”:http://freshmeat.net/projects/zenity to display dialog boxes, and we need to install it
bc. $ sudo apt-get install zenity
h3. Common steps for all devices using Rockbox
If you have a device using the excellent “Rockbox”:http://www.rockbox.org/ firmware, you now need to copy your rockbox firmware directory to the sync folder you created in your home directory a few steps back:
bc. $ cp -r /media/IPOD/.rockbox ~/rockbox/
This example assumes that your device is mounted on @/media/IPOD@. Note that this step is cruicial, or you might end up losing all of your customizations for Rockbox, and may end up with an unbootable device.
h3. rsync with automated updating of the Rockbox firmware
If your digital audio player is equipped with “Rockbox”:http://www.rockbox.org/ – follow these instructions. Otherwise, just skip to the next step.
First, go to the “Rockbox build index”:http://build.rockbox.org/, locate the correct rockbox firmware, and copy the link to that firmware. Next, copy the contents below to a file, that you save as @~/.gnome2/nautilus-scripts/Sync_now@
bc. #!/bin/bash
rsync –delete –force -irKLtWvu /media/KABOOM/.rockbox/ ~/rockbox/.rockbox/
wget -nv -O ~/rockbox/rockbox.zip http://build.rockbox.org/dist/build-ipodnano/rockbox.zip
unzip -quo -d ~/rockbox/ ~/rockbox/rockbox.zip && rm ~/rockbox/rockbox.zip
rsync –include=.rockbox -irKLtWvu –delete –force ~/rockbox/ /media/IPOD/
p. Remember to change @http://build.rockbox.org/dist/build-ipodnano/rockbox.zip@ to the actual rockbox URL for your model, or you might end up with an unbootable media player. Also, if your device mounts somewhere other than /media/IPOD/ remember to change it (and keep the trailing slashes in the path). Ditto for the ~/rockbox/ directory.
Remember to make this script executable:
bc. $ chmod +x ~/.gnome2/nautilus-scripts/Sync_now
h3. rsync for all other devices
If your player is not using rockbox, or you do not wish to update your firmware automatically, the @~/.gnome2/nautilus-scripts/Sync_now.sh@ script is simply a few lines shorter:
bc. #!/bin/bash
rsync –include=.rockbox -irKLtWvu –delete –force ~/rockbox/ /media/IPOD/
h4. rsync and whole-file synchronization
Those already familiar with rsync may notice that I’m only syncing whole files, instead of syncing only bits and pieces of them. When I originally tried using the rsync algorithm, I couldn’t unmount the device afterwards, getting complaints about too many file handles being open, and I ended up corrupting the contents of my iPod upon forcing an unmount, so this is a “better safe than sorry” approach.
h3. Restart Nautilus
To make the scripts visible in Nautilus, you need to restart Nautilus
bc. $ killall nautilus
There should now be a “Scripts” submenu in the Nautilus context menu, where your scripts are available, and you can start using the tools. When you want to make a folder available on your iPod or other media player on next sync, you select the files/folders and choose Script>create_symbolic_links. You will be prompted for a “new name” for every file, and usually, just selecting the default option should be good enough.
When you are finally ready to sync with your iPod, just select “Sync_now” in the menu, and synchronization automatically commences. You will not be given any further progress, so you can follow whatever progress meter your device offers, to decide when to eject/unmount.
h3. A word of warning
The method outlined here leaves your media/mp3 player as a perfect replica of the folder you synchronize to. This means that files that were on the media player before synchronization, but weren’t present in the folder on disk, will be *gone* after synchronization, so you _really_ want to ensure that you have copied those files that you need copied back to the device to the synchronization folder (the one named ~/rockbox/ in these examples). Don’t say I didn’t warn you.
h3. Gotchas
This method does not currently attempt any sort of disk space checking, so you might very well end up running out of disk space during the process, if you aren’t careful. To check if you have enough disk space to perform the synchronization, you can cd in to the directory containing the files you want to sync and do this:
bc. $ du -hLs
Which will list the size of all the files you are about to put on to your device. Compare this number to the “Size” column for your that shows up when you do a @df -h@ with your device mounted. To be on the safe side, you would ideally have a 0.1-0.3GB difference; your device likely uses FAT32, and therefore wastes a bit of free disk space for every file. (On a 4GB iPod Nano, a 0.1GB difference translates into having only a few MB free after synchronization.

Comments are closed.