USING RSYNC FOR REMOTE BACKUPS

Backups are a necessity in computing life. However, it's not always feasible to have a tape drive or a CD-RW drive connected to each machine. And you may not always have physical access to the remote system in question. So how do you back up data on a remote system? If you're running Linux, consider using rsync.

Rsync is a bandwidth-saving tool for transferring remote files. Unlike protocols such as FTP, which will download an entire file in the event that any part of the file is changed, rsync will download only the altered data. Thus, if you're copying log files, you may only have to download 1 MB of changed data with rsync as opposed to a much larger file with FTP.

Using rsync is relatively simple. Below is a script that employs rsync to back up Web pages from a remote Linux server:

#!/bin/sh

cd /backup

/usr/bin/rsync -avP --delete -l -t -e

ssh user@remote.com:~/public_html

This script changes to the local directory /backup. It then invokes rsync to copy all data from the remote directory ~/public_html for the user user on the remote site remote.com. The script tunnels everything through SSH for encryption and will delete any files on the local mirror that no longer exist on the remote. The result is a copy of ~/public_html from the remote system in /backup/public_html on the local system. If you run this script every night, you'll have a daily backup that can easily be restored should anything happen on the remote server.