# Automatic backup

**URL:** <https://forum.ghost.org/t/automatic-backup/19924>\
**Category:** Developer help\
**Created:** [February 3, 2021, 12:21am UTC](https://forum.ghost.org/t/automatic-backup/19924 "2021-02-03T00:21:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://forum.ghost.org/u/iero)\
**Post date:** [February 3, 2021, 12:21am UTC](https://forum.ghost.org/t/automatic-backup/19924/1 "2021-02-03T00:21:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vikaspotluri123](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/vikaspotluri123/32/24_2.png) [@vikaspotluri123](https://forum.ghost.org/u/vikaspotluri123)\
**Post date:** [February 3, 2021, 6:45am UTC](https://forum.ghost.org/t/automatic-backup/19924/2 "2021-02-03T06:45:24Z")

</div>

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

[task source](https://github.com/TryGhost/Ghost-CLI/blob/master/lib/commands/export.js)

export logic:

> <https://github.com/TryGhost/Ghost-CLI/blob/68bb91937f559e7035d46c6d78c7727035f6c501/lib/tasks/import/api.js#L127-L136>

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [February 3, 2021, 9:02am UTC](https://forum.ghost.org/t/automatic-backup/19924/3 "2021-02-03T09:02:40Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://forum.ghost.org/u/iero)\
**Post date:** [February 3, 2021, 4:42pm UTC](https://forum.ghost.org/t/automatic-backup/19924/4 "2021-02-03T16:42:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://forum.ghost.org/u/iero)\
**Post date:** [February 3, 2021, 10:17pm UTC](https://forum.ghost.org/t/automatic-backup/19924/5 "2021-02-03T22:17:43Z")

</div>

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

> [@Backup best practices](https://forum.ghost.org/t/backup-best-practices/6652/2):
>
> Hi @omisnomis wave The best way to have all the content backed up at the moment, is doing an export: [https://docs.ghost.org/faq/the-importer/](https://docs.ghost.org/faq/the-importer/) This ensures you have all the information stored in db ready to be restored on current or new Ghost instance. Then, there are 2 other parts that need to be backed up manually: The /content/images folder (or the place you have configured to store images and other assets) The theme Additionally, if you are using custom routes.yaml for dynamic routin…

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

```

---

<div class="post-metadata">

**Author:** ![jg3](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jg3/32/11758_2.png) [@jg3](https://forum.ghost.org/u/jg3)\
**Post date:** [February 28, 2021, 9:04pm UTC](https://forum.ghost.org/t/automatic-backup/19924/6 "2021-02-28T21:04:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [February 28, 2021, 10:30pm UTC](https://forum.ghost.org/t/automatic-backup/19924/7 "2021-02-28T22:30:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tully](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jeff_tully/32/4355_2.png) [@Jeff\_Tully](https://forum.ghost.org/u/Jeff_Tully)\
**Post date:** [March 2, 2021, 3:29pm UTC](https://forum.ghost.org/t/automatic-backup/19924/8 "2021-03-02T15:29:59Z")

</div>

@ 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

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [March 2, 2021, 3:42pm UTC](https://forum.ghost.org/t/automatic-backup/19924/9 "2021-03-02T15:42:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jeff\_Tully](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jeff_tully/32/4355_2.png) [@Jeff\_Tully](https://forum.ghost.org/u/Jeff_Tully)\
**Post date:** [March 2, 2021, 4:38pm UTC](https://forum.ghost.org/t/automatic-backup/19924/10 "2021-03-02T16:38:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://forum.ghost.org/u/iero)\
**Post date:** [March 2, 2021, 5:12pm UTC](https://forum.ghost.org/t/automatic-backup/19924/11 "2021-03-02T17:12:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [March 2, 2021, 5:30pm UTC](https://forum.ghost.org/t/automatic-backup/19924/12 "2021-03-02T17:30:03Z")

</div>

@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” 👍. 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.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tully](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jeff_tully/32/4355_2.png) [@Jeff\_Tully](https://forum.ghost.org/u/Jeff_Tully)\
**Post date:** [March 2, 2021, 7:37pm UTC](https://forum.ghost.org/t/automatic-backup/19924/13 "2021-03-02T19:37:14Z")

</div>

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
