Tuesday, March 23, 2010

Super simple rsync howto

This little howto contains pretty much everything you need to use rsync to back up and or synchronize two folders locally. I decided to do this writeup after after reading this article on lifehacker. I wasn't completely satisfied with the article so I did some digging to get the answers I needed. I know there's alot of rsync tutorials out there but I wrote this for my own personal use and also I tried to keep it as short as possible while explaining what's being done.

Oh, by the way rsync is really powerful and this only scratches the surface of what rsync can do. But you don't need more info to do local back ups.


Syntax:
rsync -options /source /destination 


Compare two folders
This command uses the "-v" and "-n" option to do nothing. Instead rsync prints out what would have been copied from a source folder to a destination folder. To delete files from the destination folder see notes on "--delete" below.

rsync -rvn /source /destination 

-r, --recursive recurse into directories
-v, --verbose increase verbosity
-n, --dry-run perform a trial run with no changes made


Back up one folder to another
This is all you need to back up a source directory to a destination directory. If unsure try it out with the "-n" dry run option first. To delete files from the destination folder see notes on "--delete" below.

rsync -av /source /destination 

-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
    -r, --recursive recurse into directories
    -l, --links copy symlinks as symlinks
    -p, --perms preserve permissions
    -t, --times preserve modification times
    -g, --group preserve group
    -o, --owner preserve owner (super-user only)
    -D same as --devices --specials
        --devices preserve device files (super-user only) 
        --specials preserve special files


Additional tips n tricks

Test with the "dry run" -n option first to see what files would be deleted and copied.
-n, --dry-run perform a trial run with no changes made

Delete files in the destination folder that does not exist in the source folder.
--delete delete extraneous files from dest dirs

Exclude files that you don't need for instance system files.
--exclude=PATTERN exclude files matching PATTERN
example: --exclude '.DS_Store'

Compress files during transfer to save bandwidth
-z, --compress compress file data during the transfer 



Credits
rsync - man page 
techgage.com - Backing Up Your Linux

No comments:

Post a Comment