Best way to backup ghost self hosted

There’s no wasy way to do a Ghost backup unless you go the linux bash scripting way.

You could create a cron job to do the following:

cd /path/to/ghost/
tar cvfz ghost-site/ ghost-site.tar.gz
cp -Rv /path/to/ghost/archive.tar.gz /backup/location/
mysqldump -u user -p mysqlserver (localhost) ghost_db > ghost_db.sql
mysqldump -u user -p -h mysqlserver (remote) ghost_db > ghost_db.sql
cp -Rv ghost_db.sql /backup/location/

You can put the above into a backup.sh script so you only run a single cron job instead of several.

I assume there are other ways to backup a Ghost blog, but this would automate things at least.

For multiple ghost sites you could try any one of the below scripts:

#Archive all folders in individual .tar.gz files:
for dir in `ls`; do tar -cvzf ${dir}.tar.gz ${dir}; done

or

for dir in *; do [ -d $dir ] && tar -zcf /tmp/archive/$dir.tar.gz $dir/; done

DB backup:

Export all mysql databases in individual files:
#!/bin/bash

USER="root"
PASSWORD=""

databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

for db in $databases; do
    if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
        echo "Dumping database: $db"
        mysqldump -u $USER -p$PASSWORD --databases $db > `date +%Y%m%d`.$db.sql
       # gzip $OUTPUT/`date +%Y%m%d`.$db.sql
    fi
done
3 Likes