Automatic backup

After reading the documentation, I understood that the proper way (today) to backup a ghost instance on a VPS is:

  1. Export JSON file
  2. copy the content directory

For the first one, there is two ways: using the administration interface and with ghost-cli (command line).

As I would like to do auto-backups, I would like to use the second one. But it’s interactive and so I cannot script this command:

iero@xxx:/opt/ghost$ ghost export ~/ghost_backup.json
+ sudo systemctl is-active ghost_ghost-iero-org
? **Enter your Ghost administrator email address** xxx@xxx.xx
? **Enter your Ghost administrator password** *[hidden]*
Exporting content

Is it possible to pass user/pwd in the command line ?
Or maybe bypass the autorisation for this simple ‘read’ action ?

If not possible, I will dump the database as usual. But it could be a good improvement for a future update.

The Ghost CLI is just a wrapper around the Ghost API which is why it needs your username and password:

task source

export logic:

1 Like

@iero I’m interested in what you found in the docs that indicated an export is a proper backup strategy. Can you provide a link?

An export is not a substitute for a backup, it’s designed to move content (posts, pages, members) etc from one instance of Ghost to another but it will not include certain settings or config for security reasons and also won’t include anything where the data can grow to be quite large such as your historic member and email stats.

For a proper backup you should follow standard practice for backing up files and database content, there shouldn’t be anything Ghost specific required.

1 Like

Sorry @Kevin for the confusion, I thought an export/import was a convenient way to do a backup without dumping the database.

But ok, I’ll do that and a rsync of content directory!

Thanks for your reply!

By the way, this was the post (from Ghost staff) where I found that import/export was the good way to go:

Is this the right way to backup the DB?

#!/bin/bash

GHOST_DIR=/opt/ghost
GHOST_CONFIG=config.production.json

GHOST_BACKUP_DIR=~/

ghost_db=$(jq -r '.database.connection.database' ${GHOST_DIR}/${GHOST_CONFIG}) 
ghost_user=$(jq -r '.database.connection.user' ${GHOST_DIR}/${GHOST_CONFIG})
ghost_pwd=$(jq -r '.database.connection.password' ${GHOST_DIR}/${GHOST_CONFIG})

mysqldump --user=${ghost_user} --password=${ghost_pwd} --databases ${ghost_db} --single-transaction  --no-tablespaces | gzip > ${GHOST_BACKUP_DIR}/ghost_db_`date +%Y_%m_%d_%H%M`.sql.gz
1 Like

Hi Kevin, I came here with the exact question as @iero … how to (safely) pass credentials to the ghost-cli export command.

I recognize this doesn’t include the [site]/content directory so it is technically incomplete … but with this and a one-line tar command, it is super easy to create a backup that can be re-implemented with another instance of Ghost, which is what I think I want.

An export is not a backup in the traditional sense. It’s intention is to be used for migrating content, it’s not a complete copy of your database so it won’t function as a restore point in the way a backup would. Importing will also modify ids and re-render contents so again, not what you would expect from a backup/restore.

If you’re looking for a backup I suggest you look at mysqldump or similar.

@ Kevin, I am using Mysql dump and tar of the contents folder, when I do a restore so far I have to unpublish and republish each of my posts

@Jeff_Tully what does unpublishing and republishing achieve for you after a restore? What is the restore process you are following?

I am unzipping my contents folder into the tree, and MySQL restoring the database then accessing the ghost page in chrome. When I go to /ghost and click posts and click one, I get the text but not the picture. When I unpublish, then republish, then click the little link that pops up at the bottom left, I then see the page correctly

It will be great to have a document page to summary what is the best practice regarding ghost auto backup process.

@Kevin what do you think about my script above? It is the way?

Thanks

@Jeff_Tully it’s difficult to know what’s going on there with limited details. If/when it happens you should debug what’s causing the image not to load - is it using wrong urls? is caching interfering? etc. There shouldn’t be any reason to unpublish and republish anything.

what do you think about my script above? It is the way?

@iero If it works for you and your backup/restore procedures then “it is the way” :+1:. There’s no one-size-fits-all here, it depends on how you have your self-hosted install set up and what your recovery processes look like.

1 Like

Kevin I may be dealing with " unfamiliarity " on the /ghost page, under posts, it shows JUST the text, clicking the gear icon, and then the " view post " link indeed shows the complete post. I am going to assume this is proper operation

I have never looked at the page from the visitor side hahahah

thank you for your time