Skip to content

Instantly share code, notes, and snippets.

@joewils
Last active December 29, 2020 17:55
Show Gist options
  • Select an option

  • Save joewils/1897a27b89c9758e4eba0b07a5d80f5d to your computer and use it in GitHub Desktop.

Select an option

Save joewils/1897a27b89c9758e4eba0b07a5d80f5d to your computer and use it in GitHub Desktop.
Backup WordPress to S3 using WP-CLI and Amazon CLI
#!/bin/bash
source /home/username/.bashrc
# Shell
SHELL=/bin/bash
# Email
MAILTO=foo@bar.com
# WordPress Command Line Interface
# https://wp-cli.org
# Amazon Command Line Interface
# https://aws.amazon.com/documentation/cli/
# WordPress Root
WPROOT=/path/to/wordpress/files
# Working Directory
WORK=/home/user
# Todays Date
today=$(date +'%Y-%m-%d')
# DB Backup Filename
DBNAME=mysql-$today.sql
# WP Backup Filename
WPNAME=wordpress-$today.tar.gz
# Amazon S3 Bucket
S3BUCKET=bucketname-goes-here-wordpress-backup
# Working Directory
cd $WORK
# Backup DB
wp db export --add-drop-table --path="$WPROOT" $DBNAME
# Backup Files
tar -czf $WPNAME $WPROOT
# Push to S3
aws s3 cp $DBNAME s3://$S3BUCKET
aws s3 cp $WPNAME s3://$S3BUCKET
# Remove Local Backup Files
rm $DBNAME
rm $WPNAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment