Rsync

From LQWiki
Jump to navigation Jump to search

rsync allows you to synchronize two directories that can even be on different computers. All files in the target directory will be checked and, if needed, changed to have the same content as in the source directory.

Using rsync for secure remote backups

rsync can be used locally or over the network. It supports ssh, for secure remote differential backups.

General usage:

rsync -e ssh -avz [src_path] username@hostname.com:[dst_path]

e.g.:

rsync -e ssh -avz /etc/ root@myserver.com:/etc/

To delete files that are on the destination system but no longer on the source system, use the --delete option:

e.g.:

rsync -e ssh -avz --delete /lib/ root@myserver.com:/lib/

Here's the full meal deal for doing a total system backup. This will completely duplicate one system onto another, over the Internet. Make sure the hardware, boot devices, etc are the same or you're in for trouble:

rsync -e ssh -avz --stats --progress --delete-after --exclude-from=/root/rsync-exclude / root@myserver.com:/

Note that "/root/rsync-exclude" should include things like:

dev/
tmp/
proc/
var/lock/
var/run/

Comparing directories

You can use rsync to show differences between two directories without changing anything. In the following example, your /home/myuser is compared with the same folder on computer target:

rsync -e ssh -avz --delete --dry-run /home/myuser root@target:/home

This comparison only considers timestamps and file sizes. For comparing directories based on content, use other programs, e.g. krusader.