Skip to content

Instantly share code, notes, and snippets.

@cee-chen
Last active February 20, 2017 20:30
Show Gist options
  • Save cee-chen/4037d8dcd5bca30145ab954c0208b918 to your computer and use it in GitHub Desktop.
Save cee-chen/4037d8dcd5bca30145ab954c0208b918 to your computer and use it in GitHub Desktop.
WordPress backup script
#!/bin/sh
# Automatically create WordPress database backups every week
# Delete old backups
cd /home/protected
echo "Deleting backups older than 30 days..."
find ./ -mtime +30 -type f -name '*.sql.gz' -print -delete
# Create the backup
now=$(date +"%Y_%m_%d")
echo "Saving database backup $now.sql..."
cd ../public/
wp db export $now.sql
mv $now.sql ../protected/
cd ../protected/
gzip $now.sql
# echo "WordPress DB backup saved!"
# WordPress prints its own success message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment