Skip to content

Instantly share code, notes, and snippets.

@GromNaN GromNaN/Update-WP.sh
Created Jan 10, 2011

Embed
What would you like to do?
How-to update WordPress via SSH.
# Settings
WORDPRESS=/var/www/sites/jerome.tamarelle.net/web/blog
VERSION=3.1
BACKUP=/var/www/sites/jerome.tamarelle.net/backup
# Backup files
BACKUP_NAME=$(command date +"%Y-%m-%d")
mkdir ${BACKUP}
command tar -cjvf "${BACKUP}/${BACKUP_NAME}-files.tar.bz2" ${WORDPRESS}
# Backup database
DB_HOST=$(command grep "DB_HOST" ${WORDPRESS}/wp-config.php | command sed -e "s/^.*,[ ]*'\(.*\)'.*$/\1/")
DB_USER=$(command grep "DB_USER" ${WORDPRESS}/wp-config.php | command sed -e "s/^.*,[ ]*'\(.*\)'.*$/\1/")
DB_PASSWORD=$(command grep "DB_PASSWORD" ${WORDPRESS}/wp-config.php | command sed -e "s/^.*,[ ]*'\(.*\)'.*$/\1/")
DB_NAME=$(command grep "DB_NAME" ${WORDPRESS}/wp-config.php | command sed -e "s/^.*,[ ]*'\(.*\)'.*$/\1/")
command mysqldump -u ${DB_USER} --password=${DB_PASSWORD} -h ${DB_HOST} \
--databases ${DB_NAME} > ${BACKUP}/database.sql
command tar -cjvf ${BACKUP}/${BACKUP_NAME}-database.tar.bz2 ${BACKUP}/database.sql
# Download WordPress
TMP=$(command mktemp -d)
command cd ${TMP}
command wget http://fr.wordpress.org/wordpress-${VERSION}-fr_FR.tar.gz
command tar xfz wordpress-${VERSION}-fr_FR.tar.gz
command rm -rf ${TMP}/wordpress/wp-content/
# Setup .maintenance file
command touch .maintenance
# Remove old files
command rm -rf ${WORDPRESS}/wp-includes/
command rm -rf ${WORDPRESS}/wp-admin/
# Update files
command cp -R ${TMP}/wordpress/* ${WORDPRESS}/
# Delete working files
command cd ${WORDPRESS}
command rm -rf ${TMP}
command rm ${BACKUP}/database.sql
# Clean up
command rm ${WORDPRESS}/.maintenance
command rm ${WORDPRESS}/wp-content/*/.tmp
command rm -rf ${WORDPRESS}/wp-content/upgrade
echo "Go to url/to/wordpress/wp-admin/upgrade.php"
# Restore the database backup
mysql -h ${DB_HOST} -u ${DB_USER} -p${DB_PASSWORD} ${DB_NAME} < ${BACKUP}/database.sql
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.