Debian Tutorials

Debian Tutorials


Step by step tutorials showing you how to install and configure various applications and services on Debian based Linux distros.

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories


Remote backups using rsync

adminadmin

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 [email protected]

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 [email protected]
3. The actual backup process

Backup folders using the following command

rsync -avz --progress -e ssh /var/www [email protected]: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 [email protected]:backup >> /dev/null 2>&1

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

Comments 5
  • Samuel Nogueira
    Posted on

    Samuel Nogueira Samuel Nogueira

    Author

    Awesome tutorial, extremely helpful, clean and accurate. Loved it 😉


  • Praveen
    Posted on

    Praveen Praveen

    Author

    Thank you very much.Really superb tutorials !!


  • Irving
    Posted on

    Irving Irving

    Author

    Really Helpful….nice post….thx


  • Willynux
    Posted on

    Willynux Willynux

    Author

    Thanks for the clear and concise tutorial! Nice reference.


  • Yandos
    Posted on

    Yandos Yandos

    Author

    Works great – thank you!