Backing up Using Rsync

This a short guide on how to use rsync to back up important files from your self managed machine to your DICE file space.

Introduction

The first resources you will need are the rsync man page and the rsync documentation. You also need an installation of rsync. Almost all linux distributions come with an rsync package, often installed as part of the basic installation. You should refer to your distribution documentation for more information. Mac OS X also has the rsync command line tool installed as part of the standard instalaltion and is accessible using the terminal application. Contributions for how best to install rsync on Windows are welcome.

It is worth mentioning at this point the most important command line option available when using rsync: -n (aka --dry-run). When used in conjunction with the -v (aka --verbose) option this allows you to see what will happen before you try it for real. You should always test your rsync commands with the options -v -n (this can be shortended to -vn).

Be careful, you can end up deleting files rather than copying them using rsync if you get your source and destinations wrong.

Using Rsync

At its most simple level backing up your home directory on your self managed machine can be done with the command:

        bash$ rsync -e ssh -av $HOME/ <remote user>@<remote server>:/home/<remote username>/Backup

The -e ssh option instructs rsync to use ssh as the transport mechanism and allows you to transfer files to any machine you can SSH into. The -av uses the archive mode to transfer files and requests verbose output. Note that the =/home/<remote username>/Backup directory must already exist on the remote side.

For most users this basic recipe will need a little tweaking to take into account that backing up all of your home directory is likely to be overkill and cause storage space problems on the other destination side.

A more practial example is:

        bash$ rsync -e ssh -vrlpt \
            $HOME/ \
            <remote user>@<remote server>:/home/<remote user>/Backup \
            --include "Desktop" \
            --include "Desktop/**" \
            --include "Documents"
            --include "Documents/**"
            --exclude "*"

In this example the -av options have been replaced with -vrlpt. This is because the -a option implies -rlptgoD which will attempt to preserve the group and user ownership attributes This not always suitable if the user and groups at the two ends have different meanings. This is quite likely to be the case on a self managed machine. Not using these options will ensure that the files on the remote side are owned by your remote user and the default group for your user on the remote side.

The -D option allows rsync to handle device files, however you are unlikely to have any of these in your home directory making this option unecessary.

The interesting parts are all the --include= lines and the --exclude "*".

Other Resources

This page has some Tips and Tricks. For examples of more advanced use of rsync for backup see this very good article.

-- CarwynEdwards - 21 Sep 2005

Edit | Attach | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r2 - 26 Sep 2005 - 22:54:37 - CarwynEdwards
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
This Wiki uses Cookies