I haver battled for a number of years on how to keep a laptop and a
home directory reasonably syncronised. About a year ago I decided to
solve this problem once and for all.
Below I describe Lsync, a script I wrote to do the work for me. Here is
the Lsync script for download.
Lsync is a tool to keep your home directory synchronised across multiple
systems. While there are a few solutions out there for doing this
automagically, such solutions are either still in a research phase, have
a price tag, or are designed on a different scale.
This solution is intended to be cheap, and work with most variants of
Unix. It is also intended to be used by the user who is doing updates
on one or both copies of their own home directory. It should be used
regularly, to minimise the work required at each operation, and to
reduce the risk of data loss, or insanity.
Lsync is implemented on top of the excellent OSS program rsync.
As configured, Lsync depends on bash, ssh, and a recent version of rsync
(exactly how recent I do not know). It can probably be modified to use
the (far less secure) rsh/rexec protocol, but I am not going to do this
work. So far, I have found it to work on Solaris 9, 10 and Express,
as well as Mac OS X 10.3.9. I would fully expect it to work on any
variant of Linux.
The user will need to edit the Lsync script to set the values for their
"laptop" and "master" hosts.
Lsync offers 5 basic functions:
The sync/check operations by default are done between the user's home
directories on the "laptop" and "master" hosts, but they can instead
perform the operation just on a sub-directory of the home directory.
Any operation that modifies data requires further input from the user -
either editing of the "rsync includes" file, or entering a "y" to
confirm that we really want to sync.
An advantage of using ssh as the remote shell protocol is that the user
can leverage ~/.ssh/config to specify a different username to be used on
a remote host. For example, I have the username "timc" on my laptop,
but have to use the corporate standard "tc35445" on any SWAN host
(yuck). The magic for this to happen without work on my behalf is to
put this in ~/.ssh/config on my laptop:
Host\*.sfbay
User tc35445
Unless you have seen rsync before, you will be surprised how fast it can
do it's work. I am currently syncing about 50,000 files, but if the
metadata for these is cached on both systems, a full home directory
check takes around a minute. If it is the first check of the day, it
might take 5 minutes.
In either case, it is fast enough to use at least daily, which means you
can easily have your full, up-to-date "working set" with you on your
laptop when you are out of the office, but go back to a SunRay when you
get in.
Alternatively, if you know you have been working in a sub-directory, just
specify that subdirectory, and Lsync limits its update to that directory
tree. For example:
$ Lsync L ~/tools/sh/Lsync
It is important to understand that I am using the "--delete" option to
rsync, which means that rsync will delete files on the receiver that do
not exist on the sender. This means if you delete something on one
host, it won't come back to haunt you, but it also means you must get
sync operations in the correct order with your work activity. For easy
identification, rsync tells you whenever it would have deleted or is
deleting something by prepending it with "deleting".
Also, all sync operations will act on files and directories at the same
level under your home directory on both systems. In other words, you
can not use Lsync to copy a directory to a different location on the
receiver, leaving the receiver's version of the directory in place.
This is a deliberate decision - Lsync is intended to synchronise, not to
replicate.
When I want to sync my home directory, if I am not sure what I have
modified on what directory, I first check:
d-mpk12-65-186 ) Lsync l |
Then, noticing that the only thing to delete is something I have deleted
on the sender and genuinely do not want any more, I go ahead and "make
it so":
d-mpk12-65-186 ) Lsync L |
If I want to double-check, I can now see what might be out of date
with my "master":
d-mpk12-65-186 ) Lsync m |
If I want to just sync a particular directory tree, I can specify this
as an argument after the operation letter. This will be a lot faster
than examining my whole home directory tree on both hosts. It also
ignores my "rsync includes" file.
Any absolute or relative path can be specified, but it must resolve to
something below my $HOME:
d-mpk12-65-186 ) pwd |