Apr 27
Website Mirroring
How can you be really confident of your backups? My cunning plan is to mirror my whole website back onto my home box so I can see that I have all the data safely duplicated. When I say “my plan” I really mean I stole the idea off Ralph who has had his web site served both from ihug and from his home box for ~4 years.
The content on mysite is in the MySQL database and various files. The files are easy to mirror with rsync. Getting the database mirrored has been a lot more fun.

I use a SSH tunnel to securely connect the database on the webserver with its mirror on my home box. MySQL can support SSL connections, but using a tunnel seemed easier. I didn’t want to enslave the main MySQL server on my home box so instead I run a new MySQL server with a custom socket and port. I then set this up to connect to the master server on the webserver. The commands for this are in localdbsetup.sh.
Every half an hour I have a cron job run localsync.sh which rsyncs the files across and checks that the MySQL replication is still running. I can check my data is ok just by looking at the mirrored website. Then each night localbkup.sh runs to dump the data from the mirror and tarball it up.
Seems to be working pretty well. Yes, it is massive overkill just for a simple website backup, but it was an interesting project for the long weekend.


