Skip to content

Instantly share code, notes, and snippets.

@urlicht
Last active September 5, 2016 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urlicht/ec68dcba2e22520c6de553e2c5ebc650 to your computer and use it in GitHub Desktop.
Save urlicht/ec68dcba2e22520c6de553e2c5ebc650 to your computer and use it in GitHub Desktop.
Bash script to locally backup (copy and tar) Ghost
#!/bin/bash
########## Change variables ##########
BACKUP_LOC='/home/spooky/ghost_backup/' # where to store backup
GHOST_LOC='/var/www/ghost/' # where Ghost lives
######################################
echo $(date)': backup ghost script begin'
# create backup folder
dateStr=$(date +%Y-%m-%d-%H%M)
dirName=$dateStr'_ghost_backup'
dirPath=$BACKUP_LOC$dirName'/'
mkdir $dirPath
# stop ghost service
cd $GHOST_LOC
forever stop index.js
# copy files
cp -r $GHOST_LOC $dirPath
# start the service again
cd $GHOST_LOC
NODE_ENV=production forever start index.js
# tar files
cd $BACKUP_LOC
tar -zcf $dirName'.tar.gz' $dirName'/'
# remove copied directory
rm -r $dirPath
echo $(date)': backup ghost script end'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment