[CS-FSLUG] Rsync and backup

Frank Bax fbax at sympatico.ca
Sun Aug 17 20:46:18 CDT 2008

Ed Hurst wrote:
> Needing help with rsync for a USB stick mirror of my documents:
> I do most of my work on the big home desktop machine. From time to time,
> I go places where I know I'll have some down time and take my laptop to
> keep up with research and writing. Not wishing to crowd the harddrive of
> the laptop with a mirror my $HOME from the desktop, I decided to create
> a backup on a USB stick.
> After reformatting it to ext2 (for simplicity's sake), I found a nifty
> script using rsync to create the mirror on my stick:
>    http://www.linux.com/feature/121604
> It took a little tweaking, but I managed it. However, I am a long way
> from expertise with rsync. After my first attempt to dig into it, I
> found myself lost on some jargon. I'd like to ask the list if anyone can
> simplify things for me.
> On the laptop, I'll mount the stick and work with files directly there.
> Once I have added or modified those files, how would I go about rsyncing
> back to the source on my desktop machine? Consider I do, indeed, have an
> exclude list to avoid pulling in browser cache, a folder of disk ISOs on
> my desktop, and similar stuff useless on my laptop.

YIKES!  The script has --delete option on rsync.  If you delete a file 
on USB stick; then rsync to from usb desktop; the file is deleted from 
desktop! I rarely use --delete; although it is sometimes useful.  Not 
sure why the script does 'mkdir -p' since rsync will do that (assuming 
that $TARGET already exists).

There is no need to use a script to run rsync.  Here's what I do:

rsync -anv /source /target

Simple, right?  This command will tell you what rsync WOULD have done; 
it does NOT actually copy any files.  If I like what I see; then I 
change 'anv' to 'av' and run it again and files get copied.  Nice.

rsync -anv --exclude *.iso /source /target

This will exclude any file where extension is 'iso'.

rsync -anv --exclude-file ~/exclude.txt /source /target

Now ~/exclude.txt contains a list of expressions to exclude; play with it.

This little tutorial wouldn't be complete if I didn't point out that 
/source and /target do NOT need to be local.  If either is remote; I 
typically add -z option which invokes compression (which is simply 
overhead on local copy).  This is closer to command I use most often.

rsync -anvz -e ssh fbax at remote.ca:*.doc .

Will sync all *.doc file from a remote home directory to current 
directory on current system using an ssh tunnel.  The 'remote' system 
can be on local lan or half way around the world.  You don't even need 
to use a usb stick if both laptop and desktop are connected to lan at 
the same time.

Anyway; back to your original question.  Let's say usb key is at 
/mnt/usb/ and you're copying ~/docs/ to it.  Let's exclude directories 
'iso' and '.cache'

rsync -anz --exclude ~/exclude.txt ~/docs/ /mnt/usb/

Where ~/exclude.txt contains:

That's it!  If you also put '*.iso' in the exclude.txt file; then it 
will exclude all files with iso extension, no matter what directory they 
are in.  If you want exclude directories Frank1 and Frank2; but not 
Frank0; you can use 'Frank[12]'.  Regular expressions are fun; but 
heading off-topic.


More information about the Christiansource mailing list