GHOST CMS: backup and restore ⏤ Self-hosting.

We’ve talked a lot about security… but one of the most overlooked aspects of running a website is having a backup. You must take all necessary precautions to ensure that your website is regularly and safely backed up.

GHOST CMS: backup and restore ⏤ Self-hosting.
Photo by yannick Coffi see more @ yannickcoffi -/- PRINTS -/- yC

Having a copy of all website data, such as HTML, CSS, JavaScript, images, videos, and databases that store crucial information, like user data and content management system configurations guards you against potential risks and ensures the ability to restore your website in case of data loss, hacking, or other unforeseen events.

🎧



According to IBM, The global average cost of a data breach in 2023 was USD 4.45 million, a 15% increase over 3 years. This hefty cost is a lot, especially for small businesses. No matter your industry, the size of your customer base, or how often you post content to your website, having a website backup is the digital equivalent of having a spare tire in your trunk. While you hope you not to use it, there is a certain peace of mind knowing it’s available. The same is true for website backups. BACKUPS ARE CRUCIAL [period!]


Backup Your Business

Ghost doctor


Before running into the backup we suggest that you run the following command ghost doctor first under your working directory.
Running this will check the system for potential hiccups, and provide information about what needs to be resolved if any issues arise.

See below (hiccups !!!)

$ ghost doctor
...
..
.


✔ Checking system Node.js version - found v18.19.0
✔ Checking logged in user
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
✔ Checking system compatibility
✔ Checking for a MySQL installation
+ sudo systemctl is-active ghost_localhost
Instance is currently running
ℹ Validating config [skipped]
✖ Checking folder permissions
✖ Checking file permissions
✖ Checking content folder ownership
✔ Checking memory availability
✔ Checking binary dependencies
✔ Checking free space
✔ Checking systemd unit file
✔ Checking systemd node version - found v18.19.0
One or more errors occurred.

1) Checking folder permissions

Message: Ghost can't access some files or directories to check for correct permissions.
Help: Run sudo find ./ -type d -exec chmod 00775 {} \; and try again.


2) Checking file permissions

Message: Ghost can't access some files or directories to check for correct permissions.
Help: Run sudo find ./ -type d -exec chmod 00775 {} \; and try again.


3) Checking content folder ownership

Message: Ghost can't access some files or directories to check for correct permissions.
Help: Run sudo find ./ -type d -exec chmod 00775 {} \; and try again.

Debug Information:
    OS: Ubuntu, v22.04.3 LTS
    Node Version: v18.19.0
    Ghost Version: 5.76.2
    Ghost-CLI Version: 1.25.3
    Environment: production
    Command: 'ghost doctor'

Try running ghost doctor to check your system for known issues.


As you can see from the report Ghost can't access some files or directories because of some misconfiguration permissions.
In this ie.; we have to run the following command to get it fixed.

$ sudo find ./ -type d -exec chmod 00775 {} \;

Let's break it a little.

sudo : we execute a command as root to level privileges.
find ./ : The find command is one of the most powerful tools in Linux, it searches for files in a directory hierarchy.
-type d : find all directories in the current working directory.
-exec {} \; : The execute command. True if 0 status is returned. It runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of
the command will be much less than the number of matched files. The command is executed in the starting directory. Only one instance of `{}' is allowed within the command.
chmod : change file mode bits.


Now; let's run the command one more time:

$ ghost doctor
...
..
.


✔ Checking system Node.js version - found v18.19.0
✔ Checking logged in user
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
✔ Checking system compatibility
✔ Checking for a MySQL installation
+ sudo systemctl is-active ghost_localhost
Instance is currently running
ℹ Validating config [skipped]
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
✔ Checking binary dependencies
✔ Checking free space
✔ Checking systemd unit file
✔ Checking systemd node version - found v18.19.0

All clear!

Now, let's run the backup command:

$ ghost backup
...
..
.
= Checking for deprecations
...
..


+ sudo systemctl is-active ghost_localhost
+ sudo mkdir -p /var/www/snub_test/backup
? Enter your Ghost administrator email address youremail@whatever.com
? Enter your Ghost administrator password [hidden]
+ sudo cp /var/www/snub_test/backup/content-from-v5.76.2-on-2024-01-29-00-59-18.json /var/www/snub_test/content/data/content-from-v5.76.2-on-2024-01-29-00-59-18.json
+ sudo cp /var/www/snub_test/backup/members-from-v5.76.2-on-2024-01-29-00-59-18.csv /var/www/snub_test/content/data/members-from-v5.76.2-on-2024-01-29-00-59-18.csv
+ sudo chown -R ghost:ghost /var/www/snub_test/content
✔ Backing up site
Backup saved to /var/www/snub_test/backup-from-[backup-name].zip

Ghost backup


The fastest way to perform a backup is to use Ghost CLI to automatically generate a zip file containing all of your site data using the ghost backup command. This is especially important when updating to the latest major version. This zip file including:

- Your content in JSON format.
- A full member CSV export.
- All themes that have been installed including your current active theme
Images, files, and media (video and audio).
- A copy of routes.yaml and redirects.yaml or redirects.json.


Starting Fresh: Delete Previous Content in Ghost CMS for a Clean Slate (ONLY)


To ensure a fresh backup and avoid post duplication you will need to remove all existing content through the Ghost admin interface.

Here's how you can delete content from your Ghost CMS:

  1. Log in to your Ghost admin dashboard: Access your Ghost site's admin dashboard by navigating to your site's URL followed by "/ghost" and logging in with your credentials.
  2. Settings: Go to settings (the gear or cog wheel)
  3. Navigate to Labs: On the Left end side; scroll down until you see Labs under ADVANCED.
  4. Labs menu: On the right end side; click Open and scroll all the way down.
  5. Danger Zone: Click on Delete all content. This will permanently delete all posts and tags from the database, a hard reset

Import your backup data



Once you have installed and set up your new site, it’s time to migrate your data.

Starting in your ghost folder, unzip the backup into the content folder:
sudo unzip /path/to/backup-from-[backup-name].zip -d content

a. Zip is a command-line utility tool used for compressing files and folders. Compression of files & folders enables faster and more efficient transfer, storage, and emailing of files and folders. On the other hand, unzip is a utility tool that helps you decompress files and folders.
b. if not installed sudo: unzip: command not found. proceed with sudo apt install unzip

  1. Make sure the files have the right permissions:
    sudo chown -R ghost:ghost content
  2. Restart Ghost:
    ghost restart
  3. Import your content:
    ghost import content/data/content-from-[version#].json - This requires your username and password, and can also be done on the labs page in Ghost Admin.

While backing up your website seems boring, it can be an absolute lifesaver if you find yourself in need. I cannot stress enough how crucial backups are. It's just an integral piece of security.

Keep Us Caffeinated  ⦿ ⦿