Last active
November 10, 2015 08:29
-
-
Save zarakay/4fe27d115922a2393ce5 to your computer and use it in GitHub Desktop.
Script to backup and upgrade ghost blog deployed on a digitalocean droplet
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
GHOST_LOCATION="/var/www" | |
BACKUP_PATH="/home/migara/backups/" | |
function check { | |
"$@" | |
local status=$? | |
if [ $status -ne 0 ]; then | |
echo "error with $1" >&2 | |
exit 1 | |
fi | |
return $status | |
} | |
function stop_ghost { | |
echo "Stopping Ghost" | |
check sudo service ghost stop | |
echo "Ghost Stopped" | |
} | |
function start_ghost { | |
echo "Starting Ghost" | |
check sudo service ghost start | |
echo "Ghost Started" | |
} | |
function backup { | |
# mv server.log logs/.log | |
echo "Starting Backup" | |
FILENAME="ghost_backup_$(date -d "today" +"%Y%m%d%H%M").tar.gz" | |
check mkdir -p $BACKUP_PATH | |
check cd "$GHOST_LOCATION/ghost" | |
check tar -zcvf $FILENAME content/ | |
check mv $FILENAME $BACKUP_PATH$FILENAME | |
echo "Backup Complete" | |
} | |
function update { | |
echo "Starting update" | |
stop_ghost | |
backup | |
check cd "$GHOST_LOCATION" | |
check wget http://ghost.org/zip/ghost-latest.zip | |
check rm -rf ghost/core | |
check unzip -uo ghost-latest.zip -d ghost | |
check chown -R ghost:ghost ghost/* | |
check cd ghost | |
check sudo npm install --production | |
start_ghost | |
check cd "$GHOST_LOCATION" | |
check rm -f ghost-latest.zip | |
echo "Update Complete" | |
} | |
# ensure root | |
if [ "$(id -u)" != "0" ]; then | |
exec sudo "$0" "$@" | |
fi | |
update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment