Backing up MySQL: The Last Resort Method
One of the first things I do when taking on maintenance for a web site is to do my own backups. This usually means database snapshots, and that database is usually MySQL. Unfortunately I am rarely allowed a shell login to the server, and sometimes not allowed to connect to MySQL from outside the host's network either. But one thing I can always expect is access to PhpMyAdmin, the virtually-standard web frontend for MySQL administration.
That's fine, but I need my backups automated. I found a Python program that screen-scraped PhpMyAdmin, but I ran into a big problem: the PhpMyAdmin installation for one site had a robots.txt file at its root that excluded everything. Python's urllib2 honored the robots.txt rules and I was not finding anything in its documentation on how to override it. It was time to fall back to something that would bend to my will: Perl 5 with WWW::Mechanize.
I gave it the imaginative name phpmyadmin-backup and added it to my 'futilities' collection on github. It works like this:
% phpmyadmin-backup \
--url=http://URL_of_your_PhpMyAdmin/ \
--dbname=database \
--username=username \
--password=password > BACKUP.sql.gz
If you're backing up a Wordpress site, point phpmyadmin-backup at a copy of the site's wp-config.php file and it will derive the dbname, username, and password from it:
% phpmyadmin-backup \
--url=http://URL_of_your_PhpMyAdmin/ \
--wp_conf=/path/to/wp-config.php > BACKUP.sql.gz
Your prerequisites (system requirements, if you will) are just Perl 5 with WWW::Mechanize. Also, php must be in your $PATH if you want to use the --wp_conf option.
Enjoy, but remember: this is a last resort for cases where mysqldump isn't an option. I genuinely hope you never have to use this program.