Unfortunately, I had to learn the hard way to start backing up my stuff locally, and backing that up too. On my old web host I had around 10 different websites hosted on there plus some other stuff that violated the TOS… Long story short, my host disabled my account without notice and I just lost many many hours of work and guess what, none of it was backed up.
/facepalm
So after that big fiasco and headache, no matter where something is hosted or how safe and reliable I think my data is, I always set up some sort of remote backup schedule. Since all my sites run on linux, the easiest way to do this is with rsync, crontab, and passwordless ssh.
Rsync:
This is my simple rsync command I use. I know there are some cool more advanced features of rsync like versioning and archiving but I like to keep things simple.
-v : verbose, lists exactly what files are being copied
-u : update, updates files that have changed
-r : recursive, backs up entire directories
rsync -vur /path/to/backup user@remotehost.com:/path/to/backups
Passwordless ssh
I followed a guide to get passwordless ssh working. It was the most clear, concise, and straight forward tutorial I could find. Something that confused me at first was what machine the “remote host” and what machine the “local host” was. To clarify, the remote host is the host you are trying to log into and the local host is the machine you are trying to setup passwordless ssh on.
Towards the end of the article, the author talks about setting this up so you don’t have to re-enter the id_dsa password and so that passwordless ssh can work in cron and accross multiple sessions.
But I ran into a problem when I was attempting to execute rsync from cron and I was able to get around it with this script that simply sources the .ssh-agent.sh everytime a backup occurs.
#!/bin/bash source ~/.ssh-agent.sh rsync -vur /path/to/backup user@remotehost.com:/path/to/backups
Crontab:
0 3 * * * /path/to/backup.sh > /path/to/backup.log
With this cron job it runs the backup.sh script every night at 3am and outputs stdout to backup.log
This crontab only shows what I do with rsync. I also have have a couple jobs to backup my mysql databases and puts them into one of the folders that are backed up. This can easily be done with mysqldump.
Then then I have my backups backed up to a raid 5 array on my file my file server at home. I am still contemplating whether to backup my local backups to an off site backup service.
-Adam

