Howto backup your WordPress-Blog and MySQL-data with AppleScript on MacOS X

Sun, Jul 31st, 2005 at 18:10 | Posted in Apple, metablog

I know, I know, the WordPress Backup Week is over and of course you all have already a working backup of your blog. Right? While backing up my blog and playing around with AppleScript I’ve setup a script that do can be usefull to

  • backup your Blog (all Files & MySQL-data)
  • keep a (working) copy of your blog on your local machine. Nice to tweak WordPress and do some work on the templates and to show off with your blog, when there’s no web-connection.
  • learn more about AppleScript

Download Script: backup-wordpress.zip

What the Script does

  • Download all files from your blog-directory to your local webserver-path
  • Connect to your MySQL-Server and get the database with your WordPress-data. Right now, the whole database will be copied, so if you have multiple blogs it may take some time. If you want a version that only gets the tables for your blog, leave a comment and I’ll try to modify the script.
  • Download the database-dump
  • Imports the MySQL-database on your local machine
  • Repairs the Wordpress-settings in the MySQL-database, like domainname, path to wordpress-files.
  • Backup the wordpress-directory and MySQL-data in a zip-file

What do you need?

In order to have the script working for you, you need to have:

  • MySQL installed, in order to get the data from your blog
  • Apache & PHP installed, if you want to keep a running copy of your blog
  • You need to have Transmit installed.
  • Username and database for the local copy of your blog must the identical to the mysql-username and database on your webserver, where your blog is hosted

Setup MySQL, PHP, Apache and settings for the script

  • Alastair has written a nice HOWTO: Set up a Local Mirror of your Wordpress Blog on MacOS X. Just follow the step-by-step-instructions to setup Apache, MySQL and PHP. On your local machine: Make sure to create a database, user and password that are the same, your wordpress-blog is using. If not the script will not work. Information on howto create a database, user etc. can also be found in Alastair’s howto.
  • The script will take all config-information from a file called buwp-settings.txt (you can also rename that if you want). You need to change the first line in the script to the full path and filename where this file is stored. Settings in the file are self-explaining. Take care that you don’t delete the spaces between the first description word and the setting. The script has nearly no error tracking. If you don’t want to have your MySQL and FTP passwords stored in a file just enter - and the script will ask you during execution for your passwords.

Unfortunately you need to hit enter in Transmit, when the download from your FTP-server is completed. Then the script continues. Any problems? Check if Apache, PHP and MySQL are working, is there a local database and user that equals your database and use on your remote blog? Is the Local_Webserver_Directory in bwup_settings.txt accessible by the Apache (take a look at httpd.conf and look for DocumentRoot).

Warning: Everytime you start the script the local blog-directory and database will be overwritten, everything is one-way only. A future version will be Automator-enhanced to take better care of the zipped archive file.

It seems that script is somewhat .. aehm buggy, when you’ve more than one wordpress blog in your database but since it’s working, if you’ve only one blog, I can live with that, for the moment.

Any other suggestions and improvements are welcome.

Leave a Reply