Backing Up A Funkaoshi Production

   19 February 2010, early morning

I’ve been backing up my website from my web host (Dreamhost) to my local computer automagically for the past little while. The process isn’t too complicated, so I thought it might be helpful to explain what i’m doing. There are basically two sets of data I need to copy from the remote site when doing a backup: the first are the actual files that I have stored on Dreamhost; the second is all the information stored in databases. I use rsync to copy the files, and mysqldump to copy the database data. Here is the complete script I use to perform my backup:

You use ssh to run commands on a remote machine. The first command I run is used to dump my funkaoshi database to a SQL file in a temporary directory I’ve made on Dreamhost. The reason I can run mysqldump in this fashion, without supplying a username and password, is that I store this information in the .my.cnf config file. I use the option add-drop-table when generating the dump file, because I always want a fresh copy of the data that is live. I compress the resulting file so that downloading it is faster.

You use scp to securely copy a file between two computers. I copy the file I generated from the Dreamhost server to my computer. I then decompress the file, getting the original SQL dump.

The mysql command will run the SQL stored in the database dump file. This will overwrite the contents of my development database with what is currently live.

Next I use git to backup the SQL file. I run this script every day, and for each day I will have a snapshot of what the database looked like. So even if the script overwrote my local data with garbage, I would be able to go back to a point where the data was still good.

I use rsync to keep the files on Dreamhost in sync with the files in my backup folder.

The last command updates a preference in Textpattern so that I can view the site locally, and it will behave correctly.

And that’s how you backup a website. If you see any gapping holes in what i’m doing, please let me know!



Don't be shy, you can comment too!

Some things to keep in mind: You can style comments using Textile. In particular, *text* will get turned into text and _text_ will get turned into text. You can post a link using the command "linktext":link, so something like "google": will get turned in to google. I may erase off-topic comments, or edit poorly formatted comments; I do this very rarely.