[NBLUG/talk] Seemingly excessive rsync complexity

Lincoln Peters sampln at sbcglobal.net
Sun Mar 5 14:21:28 PST 2006


I'm  trying to set up several folders to automatically synchronize 
between my desktop computer (running Debian/Etch) and my laptop (running 
MacOS X) using rsync.  Everything seems like it will work, but I did 
notice a few odd things.

The command I used on the laptop is:

# rsync -rlptg /Users/lmpeters/Documents lincoln at 192.168.1.104:~/

This seems to update and copy files from the laptop to the desktop just 
fine, but new files on the desktop do NOT get copied to the laptop.  To 
get that to work, I have to follow it up with this command:

# rsync -rlptg lincoln at 192.168.1.104:~/Documents /Users/lmpeters/

The problem is that, if I want to to tell rsync to delete a file if the 
corresponding file on the mirror was deleted, or vise versa, I could add 
the --delete switch, but it would ONLY work if the file was deleted from 
the laptop (i.e. it would delete the corresponding file from the 
desktop); if the file was deleted from the desktop, it would be 
recreated from the copy on the laptop by the first rsync command!

Looking at the man page for rsync, I see that I could probably avoid 
that problem by running the two rsync commands with both the --existing 
and --delete switches, then re-run them as shown above.  However, that 
means FOUR executions of the rsync command to synchronize ONE directory! 
  I'm pretty sure that it would work, but it seems horribly inefficient!

This means that I'd most likely use a shell script that looks like:

#!/bin/bash

for dir in <list of directories>
do
	rsync -rlptg --existing --delete /Users/lmpeters/$dir \
		lincoln at 192.168.1.104:~/
	rsync -rlptg --existing --delete lincoln at 192.168.1.104:~/$dir \
		/Users/lmpeters/
	rsync -rlptg /Users/lmpeters/$dir lincoln at 192.168.1.104:~/
	rsync -rlptg lincoln at 192.168.1.104:~/$dir /Users/lmpeters/
done


Is there a way to simplify all of this to a single rsync command?
And I should also ask: is there anything I'm doing here that is likely 
to cause data loss (e.g. is likely to delete something that shouldn't be 
deleted)?


(By the way, I'm using rsync though SSH, which is set up with host-based 
public key authentication, so even if I do have a batch process running 
dozens of "rsync" commands, at least I won't have to type in a password 
every time.)


--
Lincoln Peters
<sampln at sbcglobal.net>



More information about the talk mailing list