Now I can backup and update the blog but a few times I have had to manually import the rest of the blog data. You saw from the backup scripts in part 1 it will export the blog content as a JSON file and the content (that includes all the images used) as a ZIP file. The blog is manually imported via:
The blog content JSON file is imported from the Settings Lab Import button.
The images content is uncompressed from the ZIP file into the blog folder.
The profile is reset whenever the blog is reset and the details have to be manually updated again, the profile text and pictures.
I've done this enough times and I need to update the Ghost blog and fix any Snyk reported security issues. I need to automate and this article will show the scripts that will help import a backup automatically. These scripts are a work-in-progress because I haven't yet executed them. This code is my educated guess so far and I will update the code once I have confirmed them working.
Importing the blog content
This script will import the blog content using the datetime of the backup datetime of choice. Which is whatever I extracted from AWS S3 blog backup bucket.
What I really need to do is query the S3 bucket and give the user the option to choose which backup to download and import saving myself those extra manual steps of logging into AWS console and listing the bucket contents or using the AWS CLI. This idea is currently commented out.
The current import_website.sh script otherwise calls the import.sh script with the datetime and then runs the Cypress automation to import the blog data.
Extract the blog data
The first part of the import is to uncompress the blog backup file into the blog content location.
Automatically enter the blog data
This script will:
log into Ghost
check the blog content JSON file exists
run the test to import the blog
Currently this script will need the datetime hardcoded until it can be passed in as an argument and both the extraction datetime and the blog content datetime can be the same value. Another item on the TODO list.
Then the profile is imported with these steps:
log into Ghost
reading the profile JSON file from the expected location
Browse to the profile page
Upload the cover picture
Upload the profile picture
Enter the profile details
Once this has been fully tested then I will update this article.