Skip to content

Instantly share code, notes, and snippets.

@davidsword davidsword/backup.sh
Created Apr 18, 2018

Embed
What would you like to do?
A modified version of https://github.com/wpbullet/wp-cli-backups-cloud-storage for my specific needs
#!/bin/bash
S3DIR="s3://BUCKET_NAME"
BACKUPPATH=/tmp/backups
SITESTORE=/var/www
SITE=public_html
DATEFORM=$(date +"%Y-%m-%d")
DAYSKEEP=7
DAYSKEPT=$(date +"%Y-%m-%d" -d "-$DAYSKEEP days")
mkdir -p $BACKUPPATH
echo Backing up $SITE
if [ ! -e $BACKUPPATH/$SITE ]; then
mkdir $BACKUPPATH/$SITE
fi
echo Compressing $SITESTORE
tar -czf $BACKUPPATH/$SITE/$DATEFORM-$SITE.tar.gz $SITESTORE
echo Exporting Database
wp db export $BACKUPPATH/$SITE/$DATEFORM-$SITE.sql --path=$SITESTORE/$SITE --single-transaction --quick --lock-tables=false --allow-root --skip-themes --skip-plugins
echo Compressing Database
cat $BACKUPPATH/$SITE/$DATEFORM-$SITE.sql | gzip > $BACKUPPATH/$SITE/$DATEFORM-$SITE.sql.gz
rm $BACKUPPATH/$SITE/$DATEFORM-$SITE.sql
echo Uploading $SITESTORE zip
aws s3 mv $BACKUPPATH/$SITE/$DATEFORM-$SITE.tar.gz $S3DIR
echo Uploading Database zip
aws s3 mv $BACKUPPATH/$SITE/$DATEFORM-$SITE.sql.gz $S3DIR
echo Deleting any old backups on S3
S3REM=$S3DIR/
aws s3 rm $S3REM/$DAYSKEPT
echo Deleting all localbackups
rm -rf $BACKUPPATH/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.