Updating and Backing up WordPress


Not too long ago at work I had to come up with a solution for recurring updates and backups on multiple distinct WordPress installs. I could have used a plugin but it seemed to be an ineffcient way of going about it, since I would have to set it up on each blog separately. These days WordPress does automatically apply security updates, however it still skips non-security updates and it doesn't back itelf up before updating.

I went with making a small bash script leveraging wp-cli. It can be run straight on the server either manually or as a cron job. No plugins necessary, therefore you won't be slowing down you site at all. Maybe somebody else can find this useful, so I'm putting it up here.

You can also add it to your crontab, that would look something like this:

$ crontab -l > new_cron
$ echo "0 1 * * 2,3,4,5,6 /home/username/scripts/wp-update.sh -p /var/www/html/wordpress -b ~/backups -n 5 >/dev/null 2>&1" >> new_cron
$ crontab new_cron
$ rm new_cron