Beware this content is over 4 years old and considered stale. It may no longer be accurate and/or reflect the understanding of the author but remains here for reference only. Please keep this in mind as you use this content.

This is connected to my previous Dropbox post.

Important aspects are extracting a MySQL dump of a database (Credit: Vivek Gite) in addition to a specific folder of a website. Then placing both backup files into a Dropbox folder for safe keeping.

While I use Git to deploy my websites and therefore don’t require backing up of the entire site. Some folders with user-generated content or media may need to be specifically backed up and therefore this script could be used as the basis for that sort of functionality. Feel free to edit as needed.

Install the Script

The example script below uses a typical WordPress configuration as an example where we need to backup the wp-content/uploads directory. It also assumes you’ll be running this as root with Dropbox installed for the root user account.

The best place to store this script is in the Dropbox directory (~/Dropbox/wordpress) you want the backups to be stored. That way you can write multiple backup scripts for different sites.

Name the file

Next, make the script executable.

$ sudo chmod +x ~/Dropbox/wordpress/

Run it from the command line to test the output.

cd ~/Dropbox/wordpress && ./

All being well it should have created your backup files. You’ll want to download them and give the archives a test by extracting and importing the content.

Automate the Process

While a backup script is great its not much use if the last backup was several months or years ago and you end up losing large amounts of data since the site went live.

Save yourself the hassle of having to remember and link the script above to a cron job and let the server do the hard work.

$ sudo crontab -e