Skip to content

Instantly share code, notes, and snippets.

@parsafatehi
Forked from bradt/backup.sh
Last active October 23, 2021 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsafatehi/b3db76c821e8648214cad013030528a3 to your computer and use it in GitHub Desktop.
Save parsafatehi/b3db76c821e8648214cad013030528a3 to your computer and use it in GitHub Desktop.
Simple WordPress Backups v2
#!/bin/bash
# Change WP_PATH with your WordPress installation path
cd /WP_PATH
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
# Backup plugins directory
tar -zcf ../backups/${NOW}_plugins.tar.gz wp-content/plugins
# Remove backup files that are 7 days old
rm -f ../backups/$(date +%Y%m%d* --date='7 days ago').gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment