Back Up Your Ghost Blog with Google Drive

Introduction

I recently set up a new blog using the Ghost blogging platform on a self-hosted AWS EC2 instance. With many thanks to my years of experience as a DevOps Engineer, I was able to set up a snapshot policy to fully back up the drive of the instance each night. However, this isn’t a free option, and I’d like a more modular way to back up just the blog itself and its corresponding configurations. This way I could easily export my blog to another hosting platform if I were to choose to do so.

I began to search around for the cheapest (ideally free) options available. There were a few criteria that had to be met for this solution.

  1. Utility, app or a script to execute the backup.
  2. A location to store the backup.
  3. Some kind of versioning system that allowed me to pick and choose which backup to restore.

Working backward I decided it was easiest, and free, to use the cloud storage provider I already use every day, Google Drive. This solution would knock out two of my criteria, a location to store the backup, as well as a handy versioning system already built into the application. That leaves with one last requirement, the actual utility that will perform the backup. Enter ghost-backup.

  1. Schedules a daily task to perform the backup.
  2. Automatically outputs the backup archives in your Google Drive.
  3. Ability to get a notification (via Telegram) about the status of your most recent backup.

Setup

Setup is quite simple and only involves two commands. The only prerequisite is that you must have Python 3 installed and configured. Follow this tutorial if you need help doing so.

git clone https://github.com/gonzolively/ghost-backup && cd ghost-backup

python3 setup.py

After running this script you’ll be taken through an interactive setup process, albeit crude and command-line based. In addition to backing up your blog posts, you can also back up the images and themes of your blog.

First, you will be prompted to choose whether or not you’d like to back up the images in your blog.

The second step prompts you whether or not you’d like to backup your theme.

Next, you will be prompted for your app name. This name will be used as a part of the filename format to provide more detail. This is useful if you have more than one blog on the server and subsequently more than one backup file.

The fourth step prompts you for the MySQL hostname (i.e. the hostname of your machine). In 99% of cases, I recommend the default of localhost.

Then you will be prompted for your MySQL database user's username.

The sixth step prompts you for your MySQL database user's password.

Lastly, you will be prompted for the database name in which your blog is stored.

Once this step is completed you’ll be prompted to authenticate your Telegram account if you chose to get back alerts. After that setup is done. Your blog is now able to backup to google drive! The next sections will discuss in more detail the backup file format and how to restore your blog using this file.

Example: appname-20190325142251.tar.gz

  1. appname = Value entered in step 3.
  2. 20190325142251 = Timestamp string including Year/Month/Day of Month/Time. (See chart below for more details.)
Backup file format

Restoring your blog from the backup file created by ghost-backup is a very easy and seamless process. Follow these simple steps.

  1. Head over to your Google Drive account and download the backup file.
  2. Use SCP, FTP, or your favorite file transfer utility to get the backup file onto your server.

3. Unpack the archive using the following command.

tar -xvzf appname-timestamp.tar.gz

4. Jump into the new directory that was created after un-archiving your file.

cd appname-timestamp/

5. Inside this directory you’ll find a file ending in .sql, this is the SQL database dump file. The next step is to dump that SQL file back into your database with the following command.

mysql -h <hostname> -u <user> -p <password> dbname < filename.sql

(Note: You’ll need to replace the above variables for your specific configuration.)

Conclusion

That’s it! There’s not much more to this utility than what you saw. It provides simple, reliable, and quick backups of your Ghost blog with minimal fuss. Feel free to submit a pull request to my repository if you find a bug, or would like to add a feature. I hope you’ve enjoyed this post and enjoy using ghost-backup. Please check out more of my posts as I routinely post about DevOps, Software Engineering, and Web Hosting on a routine basis.

Thanks!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Knox Lively

Knox Lively

Lead Tech Evangelist at Observe, Inc. — @KnoxLively