Skip to content


Automating rsnapshot backups

In my earlier tutorial, I showed you how to do manual backup with rsnapshot. You should have completely followed that tutorial before continuing on with this one. In this how-to I will describe how to automate rsnapshot backups.

First we need to create private/public keys on our backup server

ssh-keygen -t rsa

and accept the defaults if presented any by pressing Enter. Don’t put in any passphrase. It will create two files id_rsa and id_rsa.pub in /home/usename/.ssh/. id_rsa is the private key that you never give out to anyone and id_rsa.pub is the public key and can be given freely to anybody.

Next we need to copy id_rsa.pub to the host being backed up and put it in its authorized_keys file. So first copy it to mars (remote host) with the following command. Suppose we are in /home/username/ directory

scp .ssh/id_rsa.pub root@mars:

The above command will copy id_rsa.pub to root’s home directory on mars.
Use ip instead of name ‘mars’ if you have problem with name resolution. To setup DNS for name resolution, checkout this tutorial.

Now on mars, cat the contents of id_rsa.pub into the authorized_keys file located in /root/.ssh using ssh

ssh root@mars "cat /root/id_rsa.pub >> /root/.ssh/authorized_keys"

(Note the file that the public key should go into maybe named differently or at different location. Look for the exact location in /etc/ssh/sshd_config for the value of the parameter AuthorizedKeysFile).

At this point, you should be able to ssh into mars from backup server without supplying any password.

Next, we need to configure cron. We will backup everyday at 0900 PM.

In /etc/cron.d/rsnapshot

Paste the following:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

00 21 * * *     root  /opt/bin/rsnapshot -VV -c /etc/rsnapshot/mars-daily.conf daily

Save and let rsnapshot does its magic.

In another tutorial, I will show you how to create a script that will alert you only when backups fail.

 

Share The Knowledge:
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • blogmarks
  • Diigo
  • E-mail this story to a friend!
  • LinkedIn
  • Live
  • Reddit
  • StumbleUpon
  • Twitter
  • Blogosphere News
  • Identi.ca
  • Slashdot
  • Technorati

Posted in Backup, Centos, Debian, Fedora, Red Hat, Ubuntu.

Tagged with , , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.