I have been running multisite WordPress on my Amazon EC2 instance for almost a year and now that I have four sites running concurrently it is time to sort out a proper backup routine. Having had a look at all of the options and plugins it seemed like a good idea to backup WordPress to Dropbox and because of the size of my instance wouldn't cost anything. I also wanted full control via Linux rather than installing a plugin which I didn't trust. Also a good chance to do some more learning. Figured it would be a good idea to put the steps here so someone else can create should they want to do the same. I decided to run Dropbox under the ec2user as that is how everything else on my server is setup.
Download the latest stable Dropbox.
You should get a message saying your account isn't syncing and to visit a URL. Copy the URL to a browser and login. Wait for the welcome message and then use Ctrl-C to exit. Now lets ensure that Dropbox will start when we restart our instance. Create a startup script.
If you are using a stock Amazon Centos OS then copy the below. If not check for a script at the bottom of this page.
daemon --user $dbuser /bin/sh -c "~$dbuser/.dropbox-dist/dropboxd&"
Now we need to add a file which contains the ec2-users that we want to run the service.
Now we need to sort the file permissions.
Check that it worked, look for Dropbox in the list.
Hopefully everything should now be working fine.
I moved my Dropbox folder to my EBS volume so it would persist, then symbiotically linked it back to the home directory.
Now it is time to tidy up the directories where Dropbox sit and ensure that only the folders you want synced are turned on.
We now need to download the Python Script which is used to manage Dropbox from the Command Line and give it the right permissions.
Hopefully should now be syncing up, most likely you won't want everything to sync so you can use the 'exclude add' command to stop folders you don't need. Run the below and it will show your synced folders.
You can stop each of them syncing by using the following command.
If you run the below again you can see that they are dropping off.
Also worth turning off LAN sync as you won't need it.
Create a folder for backups.
Now we want to write a quick script to copy the files from html/wp-content to Dropbox/Backup/wp-content and dump the MySQL. Create the below file, it should be synced to your other computers as soon as you save.
Here is the script, change the paths /vol/html/ to where you have your wp-content folder and /vol/Dropbox/Backup to where your Dropbox sits, plus update your MySQL password.
echo "Syncing wp-content Files from html to Dropbox"
Now we have our script sorted we need to create a cron job to run it once a day at 1am. You will need to stop cron.
Now lets edit the file which runs our jobs.
Save and start cron backup.
You can now rest easily that every night at 1am you can backup wordpress to dropbox including the entire wp-content folder plus a database dump. Perfect for the small time blog runner. Props to the following sites that were a big help in this process.
Richie Hawtin – Essential Mix: Live At Watergate, Berlin. Hopefully shouldn't take you two hours to do this but this is just the type of mix to get lost in code to. Off to Berlin next month and if I hear anything like this I would be very happy.