Skip to content

Instantly share code, notes, and snippets.

@mrhahn3000
Created October 3, 2017 17:27
Show Gist options
  • Save mrhahn3000/2927ba3bad599be7acfb662b6dd63393 to your computer and use it in GitHub Desktop.
Save mrhahn3000/2927ba3bad599be7acfb662b6dd63393 to your computer and use it in GitHub Desktop.
A script for creating a backup of the Ghost Blog content (folder and database).
#!/bin/bash
#
echo "Create backup of ghost ... please wait ..."
DINFO=`date +%F`
GHOST_DIR=/path/to/ghost/install
DB_NAME=NAME-OF-YOUR-GHOST-MARIA-DB
BACKUP_DIR=/opt/backups
tar -cjPf $BACKUP_DIR/$DINFO-ghost-backup.tar.bz2 "$GHOST_DIR/content/"
echo "Backup created."
echo "Delete all backups except the last 5 ... please wait ..."
ls -tr $BACKUP_DIR/*-ghost-backup.tar.bz2 | head -n -5 | xargs --no-run-if-empty rm
echo "Old backups deleted."
echo "Create backup of ghost database ... please wait ..."
mysqldump $DB_NAME > $BACKUP_DIR/$DINFO-ghost-dbdump.sql
tar -cjPf "$BACKUP_DIR/$DINFO-ghost-dbdump.tar.bz2" "$BACKUP_DIR/$DINFO-ghost-dbdump.sql"
rm $BACKUP_DIR/$DINFO-ghost-dbdump.sql
echo "Backup of ghost database created."
echo "Delete all database backups except the last 5 ... please wait ..."
ls -tr $BACKUP_DIR/*-ghost-dbdump.tar.bz2 | head -n -5 | xargs --no-run-if-empty rm
echo "Old database backups deleted."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment