#!/bin/bash
source /home/username/.bashrc
# Shell
SHELL=/bin/bash
# Email
MAILTO=foo@bar.com
# 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