A couple of weeks ago, Ashley showed us how to automatically create simple backups of your WordPress site on your server. In this article I’m going to expand on that, showing how we can automatically remove old backups and copy backups to Amazon Glacier for safer storage. Removing Old Backups First, let’s add a line to Ashley’s script to remove old backups. rm -f $(date +%Y%m%d* --date='1 month ago') I’m using a date command to get the date 1 month ago and removing any backup files created 1 month ago. For example, if the script is running on July 24th, it will remove any backups created on June 24th. So as long as your script runs every day, it will cleanup backups from a month ago. It’s worth noting that the date command is different on OS X, so you will need to use the following instead. rm -f $(date -v-1m +%Y%m%d*) Compressing Backups Since we’re going to be transferring backup files and paying for storage, it makes sense to compress our backups. Doing that is as simple as running the gzip command. Here’s what our script looks like now: As you can see, I’ve rejigged things a bit. I’ve added hours, minutes, and seconds to the date string so we can run it more than once per day and
Share This