My wife’s website is built on
Wordpress. Wordpress uses a
MySQL (or MariaDB) database to
store pages, posts, comments, sessions, and everything else except media. That
database needs to be backed up regularly in case of data loss. Backing up a
MySQL database is easy - just run
mysqldump - so why
would I need anything else? I wrote
backup-wordpress
to wrap some extra functionality around mysqldump
:
- Extract the username, password, and database name from the Wordpress
wp-config.php
and pass them as arguments tomysqldump
, so you can just runbackup-wordpress /path/to/wordpress-base
, e.g. incron(8)
. - Run mysqlcheck to repair and optimise the database.
- Run
mysqldump
with the right arguments and compress the output. - Run tmpreaper to delete old
backups.
tmpreaper
is run under flock so that parallel invocations ofbackup-wordpress
won’t result in parallel invocations oftmpreaper
. When twotmpreaper
instances run in parallel, it’s possible that both will callreaddir(3)
, one willstat(2)
thenunlink(2)
a file, and the second will then fail tostat(2)
that file, resulting in error messages.
I run this for both the dev and production instances of my wife’s website every
hour from cron(8)
.