Skip to content

Instantly share code, notes, and snippets.

@juanpabloprado
Created September 17, 2016 00:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloprado/2a308d963c9257420279ddb63b5d22bc to your computer and use it in GitHub Desktop.
Save juanpabloprado/2a308d963c9257420279ddb63b5d22bc to your computer and use it in GitHub Desktop.
#!/bin/bash
cd /var/www/html
NOW=$(date +%Y%m%d)
SQL_FILE=${NOW}_database.sql
# Backup database
wp db export ../backups/$SQL_FILE --add-drop-table
# Compress the database file
gzip ../backups/$SQL_FILE
# Remove backup files that are a month old
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