Whatever you do with your computer, it’s absolutely vital to back up your data. Never is this more true than when you’re administering a website, where creating backups should be a well organised and regular procedure.
This site is no exception to that rule, so to help me out with my daily backups I’ve written a small program in the Python programming language which automates the process of archiving daily snapshots of my site. For peace of mind, I still prefer to launch and organise backups myself rather than use completely automatic solutions; this program helps make that process much quicker.
You can download the program by right-clicking here and pressing ‘Save As’/’Save Target As’.
If you want to download straight to your Linux machine from the command line, use wget:
$ wget http://zebpedersen.co.uk/python/wordpressbackup
The program is designed to run under Linux, but theoretically it will work on any Unix system (Mac OS X, Solaris etc…) with Python installed.
All you need to feed the program is the path to your WordPress installation (the directory containing your wp-****.php files). The database login credentials are borrowed from WordPress, and the backup is placed in a date-stamped folder for easy archiving.
Each backup contains a dump of your MySQL database and a tarball of your installation directory – everything you need to restore your site in case of a disaster. The backup will be created in the folder from which you start the program.
To launch the program:
$ ./wordpressbackup /path/to/wordpress/installation
For example, if your site is located in the directory ‘/home/randymarsh/web’, the command would be:
$ ./wordpressbackup /home/randymarsh/web
If you need help or more information, use the help & about functions:
$ ./wordpressbackup help
$ ./wordpressbackup about
Hopefully this little script can help out anyone else like me who only trusts a backup they’ve done by hand. Enjoy!