Last active
December 24, 2016 06:26
-
-
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"
This file contains hidden or 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!