The main problem that arises when using several computers is how to keep files synchronized. There are dozens of solutions, and mine is probably not the optimal one. However, these tricks work out for me and I want to share. Besides, I just want to put down some of those long pipes I constructed, so that I don’t need to keep them in my mind.

My computers are located in different places, are all behind NATs and thus cannot be accessed from the internet. The first step was to connect them into a common local network by setting up a VPN. As I have no computer accessible from the internet, I can not deploy my own VPN, so I have to use someone else’s server. I used Hamachi.

Next, I installed ssh servers on all my computers. The most energy-efficient one is turned on most of the time, waiting for its master to connect. And so the master does, and very often.

Then I installed Dropbox — out of the necessity to synchronize some files automatically between computers, rather then out of desire for more storage. I am very far from exhausting my quota and I seldom access my Dropbox files from other computers.

THat’s fine, but what if I need to fetch files from other computers and these files are not in Dropbox? The Dropbox way would be to log into the remote computer via ssh, copy the required file into ~/Dropbox and wait a short while. What if I need to put some files in a remote computer outside of the Dropbox folder? Again, I’ll have to connect through ssh. So, it’s “Dropbox, then ssh”, or “ssh, then Dropbox”. Can it be done easier? Sure!

If it’s just one file, I use scp. However, scp itself uses ssh, and besides this, it’s said to be quite slow. So when there are large (or just many) files to be copied over network, then I turn to plain ssh. Join the files into a tarball, feed it to ssh and have it un-tarred at the destination. A typical pipe to copy file to a remove machine looks like this:

find . [options here] | xargs tar cf - | ssh remotehost "cd /destination/folder && tar xf -"

The opposite would be:

ssh remotehost "find [options here] | xargs tar cf -" | tar xf -

The same thing can probably be accomplished with rsync, but I never tried.

Leave a Reply