Automatic backups to remote machine

Update: SSH public key authentication isn’t supported on the system I want to backup to, so I’ve changed the procedure to create a cron job on the server instead of the client.

Backups are nice, but they can be a royal pain to set up and verify, and there’s a lot of tools available. Here’s the simplest recipe I could make using standard GNU/Linux tools. I’m no security or Linux expert, so don’t expect any guarantees, and verify anything you’re not sure about.

Text like this should be replaced by values relevant for your situation.

Login to the server:
ssh backup_server

Create SSH keys without password:
ssh-keygen -P "" -f ${HOME}/.ssh/backup_id

Verify that the file was created:
ls ${HOME}/.ssh/backup_id

Copy the public key to the client machine:
ssh-copy-id -i ${HOME}/.ssh/backup_id user@client

Verify that you can login without providing a password:
ssh -i ${HOME}/.ssh/backup_id user@client

Open crontab (CERN users, please see below):
crontab -e

Add the following to the file, save and exit:
@midnight ssh -i ${HOME}/.ssh/backup_id user@client "tar zcf - backup_directory" > ${HOME}/backup/$(date --iso-8601).tar.gz

CERN specific crontab setup on LXPlus:
acrontab -e
0 0 * * * lxplus ssh -i ${HOME}/.ssh/backup_id user@client "tar zcf - backup_directory" > ${HOME}/backup/$(date --iso-8601).tar.gz

Verify that backups are created:
ls -la ${HOME}/backup/

Please comment if you have any suggestions to improve the procedure, preferably with code or shell output.

Sources:

  • Passwordless logins: 1, 2, 3
  • RSA vs DSA: 1, 2
  • man pages