Skip to content

Instantly share code, notes, and snippets.

@etiennetremel
Last active December 24, 2016 06:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save etiennetremel/6758984 to your computer and use it in GitHub Desktop.
Save etiennetremel/6758984 to your computer and use it in GitHub Desktop.
Update WordPress folder with the latest version, backup files and SQL Usage: sh update-wordpress "wordpress-directory-to-update"
#!/bin/bash
# Update WordPress folder with the latest version, backup files and SQL
# Usage: sh update-wordpress "wordpress-directory-to-update"
# Define variables
BLOG_DIR=/home
BACK_DIR=/home/wp-backups
DATE=`date +%Y%m%d`
INSTANCE=${1}
# If there's no variable, explain usage and exit
if [ -z "$1" ]; then
echo "usage: sh $0 \"wordpress-directory-to-update\""
exit 0
fi
# Backup existing database and wordpress directory
mkdir -p ${BACK_DIR}/${INSTANCENAME}/${DATE}
mysqldump -u root ${INSTANCE}_wp > ${BACK_DIR}/${INSTANCENAME}/${DATE}/${INSTANCE}.db.sql
tar -zcvf ${BACK_DIR}/${INSTANCENAME}/${DATE}/${INSTANCE}.tar.gz ${BLOG_DIR}/${INSTANCE}/public_html
# Download latest WordPress CMS
cd /tmp
wget http://wordpress.org/latest.zip
unzip latest.zip
# Overwrite all new files and cleanup
if [ $? -eq 0 ]; then
cd ${BLOG_DIR}/${INSTANCE}/public_html
cp -avr /tmp/wordpress/* .
rm -rf /tmp/wordpress
rm -f /tmp/latest.zip
rm -f readme.txt
rm -f wp-config-sample.php
chown -R ${INSTANCE}:${INSTANCE} *
echo "WordPress updated"
else
echo "Error failed to unzip or download failed"
fi
exit 0
@projectivemotion
Copy link

Best script I've seen on git for updating wordpress! Would've been perfect for use if it accepted BLOG_DIR and BACK_DIR but It looks like you already have a set use case for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment