Remote backups using rsync

rsync is a software application for Unix systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction. rsync can copy or display directory contents and copy files, optionally using compression and recursion.

We’re going to configure a machine to sync files from a specific folder to a remote machine every day using rsync in four easy steps. This is ideal solution to do automated backups for servers and workstations.


1. Configure remote machine (if not using service by a third party)

Install rsync, it must be installed on both remote and local machines to be able to sync data

apt-get install rsync

Create a new user used by the local machine to connect to the remote machine

adduser user1 --home /home/user1

Replace user1 with your preferred username. You can set any password you like and make it complicated because it’s only needed once.
2. Configure the local machine (the one being backed up)

Install rsync

apt-get install rsync

Create a private key to avoid passphrase popup to be able to do automatic backups

ssh-keygen -t dsa

Copy the key to the remote machine

ssh-copy-id -i .ssh/id_dsa.pub user1@remote.machine.com

Replace user1 with your username and remote.machine.com with the remote machine’s hostname or ip address

The link between the two machine is set up and you no longer need password to connect to the remote machine using ssh. You can try: ssh user1@remote.machine.com
3. The actual backup process

Backup folders using the following command

rsync -avz --progress -e ssh /var/www user1@remote.machine.com:backup

Using this command, all files in the /var/www folder will be synced to the remote machine into a folder named backup
4. Automate the backup using cron

Open the cron config file for current user

crontab -e

Add a line similar to the following into the config file

0 3 * * * rsync -az -e ssh /var/www user1@remote.machine.com:backup >> /dev/null 2>&1

Your /var/www will be synced to the remote machine at 3am every day

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Installing Postfix with MySql backend and TLS

In this tutorial we’ll install a ready to use Postfix mail server with MySql backend for virtual...

Installing ionCube

ionCube protects software written using the PHP programming language from being viewed,...

Installing PowerDNS on etch/lenny

The PowerDNS Nameserver is a modern, advanced and high performance authoritative-only nameserver....

Installing Zenoss monitoring system

Zenoss is an award-winning open source IT monitoring product that effectively manages the...

Upgrade from etch to lenny

Debian has released a stable version of Debian 5.0 (lenny). If you’re running previous version of...