RSync Backup with SSH

1. On the Source Server generate an RSA key for use by ssh:

> ssh-keygen -t rsa -N "" -f /root/.ssh/id_rsa

2. Copy the contents of /root/.ssh/id_rsa.pub on the Source Server to
/root/.ssh/authorized_keys on the Destination Server. Make sure that
there are no line breaks in the copied key.

3. On the Source Server, verify that you can login to the Destination Server
via ssh without a password:

> ssh -l root {ip of dest server}

4. On the Destination Server, create a directory to store the backup data:

> mkdir /backups/mail

Make sure that the selected location has sufficient available storage to accomdate
the backup.

5. On the Source Server, create a script similar to:

  #!/bin/bash

  DEST=root@172.16.11.12:/backups/mail
  OPTIONS="-e ssh --checksum --partial --delete --verbose --progress --archive --links"

  SRC=/etc
  rsync $OPTIONS $SRC $DEST

  SRC=/home
  rsync $OPTIONS $SRC $DEST

  SRC=/var/spool/mail
  rsync $OPTIONS $SRC $DEST

  SRC=/var/www
  rsync $OPTIONS $SRC $DEST

Modify the script as needed to copy the appropriate directory trees.

The script can be placed in /usr/local/sbin/dobackups.sh and should be made
executable with:

> chmod 755 /usr/local/sbin/dobackups.sh

6. Add a cron job to run the script on a nightly basis. On RedHat we can place a
file named "backups" into /etc/cron.daily with the contents:

  #!/bin/sh
  renice +19 -p $$ >/dev/null 2>&1

  /usr/local/sbin/dobackups.sh

Make the file executable with:

> chmod 755 /etc/cron.daily/backups
blog comments powered by Disqus