Rsync
From Wsms
Note: This page should be titled rsync (all lowercase). It is rsync due to technical limitations of Mediawiki.
rsync is a backup utility. It can operate locally or over the network via ssh. It is very efficient in comparing directory and files and only copies the parts that have actually changed.
Contents |
common usage
This command uses ssh to copy a directory tree across the network preserving the file attritubes:
[ggeller@ws05 public_html]$ rsync -av php/ georgeg@rop.ncc.sdccd.net:public_html/php/ georgeg@rop.ncc.sdccd.net's password: building file list ... done ./ 20070321/ ...
Tips
Use the -n option to see what would be copied without actually performing the action.
You can set an ssh key up so that you don't have to log in manually. See Rsync_with_ssh_keys.
Sirhc reports two rsync implementations that work with Windows: "I've used rsync-over-ssh using cygwin. Alternatively, winscp has a sync feature"
You can exclude an entire directory tree (or a single file) with the --exclude directive.
[ggeller@ws05 rsync-test]$ rsync --exclude=archive -avn source/ dest/
Limit the bandwidth usage with the --bwlimit flag:
ggeller@grant:~$ rsync -av --bwlimit=32 /home/ggeller/backup hayes_backup@cleveland:
Sometimes it is tricky to specify directory names if they have spaces in them. You need to use both quotes and backslashes. Alternatively consider using an *.
[ggeller@localhost test]$ rsync -av '192.168.2.12:/mnt/sda5/vmware/Virtual\ Machines/Windows\ XP\ Professional' . ...
rsync with snapshots
Here is a script I adapted from Backup & Recovery by W. Curtis Preston to quickly backup my Windows XP partition. I boot the Windows machine with a Knoppix thumb drive, mount the Windows partition as /media/sda1, and run this script on my server.
#!/usr/bin/env bash # GGG # 20090507 # Adapted from "Backup and Recovery" by W. Curtis Preston, page 189 # link-dest doesn't work for me unless I specify the full path # the x41 is not at a static IP, so this may have to be modified. rsync -rtv --delete --link-dest=`pwd`/sda1/sda1.0/ --exclude=/hiberfil.sys --exclude=/pagefile.sys 192.168.2.103:/media/sda1/. sda1/sda1.inprogress/ [ -d sda1/sda1.2 ] && rm -rf sda1/sda1.2 [ -d sda1/sda1.1 ] && mv sda1/sda1.1 sda1/sda1.2 [ -d sda1/sda1.0 ] && mv sda1/sda1.0 sda1/sda1.1 [ -d sda1/sda1.inprogress ] && touch sda1/sda1.inprogress && mv sda1/sda1.inprogress sda1/sda1.0
see also
man rsync
Linux_commands
Rsync_with_ssh_keys
