Skip to content

Instantly share code, notes, and snippets.

@phillcoxon
Forked from bradt/backup.sh
Created November 1, 2016 11:20
Show Gist options
  • Save phillcoxon/827bbdbdf9d7690b25b76781123c1156 to your computer and use it in GitHub Desktop.
Save phillcoxon/827bbdbdf9d7690b25b76781123c1156 to your computer and use it in GitHub Desktop.
Simple WordPress Backups v2
#!/bin/bash
NOW=$(date +%Y%m%d%H%M%S)
SQL_FILE=${NOW}_database.sql
# Backup database
wp db export ../backups/$SQL_FILE --add-drop-table
# Compress the database file
gzip ../backups/$SQL_FILE
# Backup uploads directory
tar -zcf ../backups/${NOW}_uploads.tar.gz wp-content/uploads
# Remove backup files that are a month old
# If running on OS X, the date command is a bit different:
# rm -f ../backups/$(date -v-1m +%Y%m%d*).gz
rm -f ../backups/$(date +%Y%m%d* --date='1 month ago').gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment