Created
May 9, 2015 17:52
-
-
Save crypticsoft/3932aebf97414824ebd2 to your computer and use it in GitHub Desktop.
WP backup shell script using wp-cli and aws-cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
export THEDATE=`date +%d%m%y%H%M` | |
export THETHEME=`wp --allow-root theme list --status=active --field=name` | |
export THESITE=`wp --allow-root option get siteurl | awk -F/ '{print $3}'` | |
export THEBACKUPS="/usr/share/nginx/backups" | |
export THEBASEPATH="/usr/share/nginx/www" | |
export THEBUCKET="bucket-name-goes-here" | |
# backup the db | |
wp --allow-root db export - | gzip > ${THEBACKUPS}/dbbackup_${THEDATE}.sql.gz | |
# backup the wordpress files | |
tar czf ${THEBACKUPS}/sitebackup_${THESITE}_${THEDATE}.tar -C \ | |
${THEBASEPATH}/wp-content/themes/${THETHEME} \ | |
${THEBASEPATH}/wp-content/uploads \ | |
${THEBASEPATH}/wp-content/plugins | |
# snapshot of the WP version, active plugins and active theme | |
wp --allow-root core version --extra | cat >> ${THEBACKUPS}/wpinfo_${THEDATE}.txt | |
wp --allow-root theme status | cat >> ${THEBACKUPS}/wpinfo_${THEDATE}.txt | |
wp --allow-root plugin list | cat >> ${THEBACKUPS}/wpinfo_${THEDATE}.txt | |
# delete older backups that were last modified more than 7 days ago | |
find ${THEBACKUPS}/site* -mtime +7 -exec rm {} \; | |
find ${THEBACKUPS}/db* -mtime +7 -exec rm {} \; | |
find ${THEBACKUPS}/wp* -mtime +7 -exec rm {} \; | |
# sync to object store bucket using awscli | |
aws --endpoint-url https://objects.liquidweb.services s3 sync ${THEBACKUPS} s3://${THEBUCKET} --delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment