Automatic backup using rsync


I’ve suddenly lost all the files in my home folders, and I quickly do these to not let the impact to be as bad, if it ever recurs.

Say 192.168.1.10 is my backup server (anduril), herugrim is my laptop’s name, these are the steps I did to let my laptop automatically rsync to the backup server.

Configure Password-less Login

Generate RSA key for use with SSH. Make sure you dont use any passphrase.

shakir@herugrim ~ $ ssh-keygen -t rsa -C shakir@192.168.1.10
Generating public/private rsa key pair.
Enter file in which to save the key (/home/shakir/.ssh/id_rsa): /home/shakir/.ssh/id_rsa.192.168.1.10
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/shakir/.ssh/id_rsa.192.168.1.10.
Your public key has been saved in /home/shakir/.ssh/id_rsa.192.168.1.10.pub.
The key fingerprint is: 11:d9:23:2e:68:05:59:d9:ac:5a:00:69:17:3a:b4:24  

Copy the public key to the server

shakir@herugrim ~ $ ssh-copy-id -i .ssh/id_rsa.192.168.1.10.pub shakir@192.168.1.10

Test if passwordless login successful

shakir@herugrim ~ $ ssh shakir@192.168.1.10 -i .ssh/id_rsa.192.168.1.10
shakir@anduril:~$

Configure Target Directory

shakir@anduril:~$ mkdir backup/herugrim -p

Manual Rsync (test power)

shakir@herugrim ~ $ rsync --verbose --progress --compress --rsh=ssh --recursive --times --perms --links --delete /home/shakir anduril:/home/shakir/backup/herugrim -e "ssh -i /home/shakir/.ssh/id_rsa.192.168.1.10"

Configure cron

At your machine To edit your crontab entry, issue this command

crontab -e

Add this entry to your crontab

30      9       *       *       1-5     rsync --compress --rsh=ssh --recursive --times --perms --links --delete /home/shakir anduril:/home/shakir/backup/herugrim -e "ssh -i /home/shakir/.ssh/id_rsa.192.168.1.10"

Run cron

sudo /etc/init.d/cron start     #depending on your linux distro

And I guess that’s all..

backup guys, backup… :)


Tags: , ,

Leave a Reply

Advertisement