From time to time you might want to migrate your website to a different server/VPS provider. This tutorial highlights some steps you should be very careful about. Improper operation may result in loss of data or files of the website.
Know Your Ghost Site
Before we start off the migration, it's better to fully understand the file and data structure of any Ghost website. So you will have an idea of what we are going to do in the following steps.
When we installed a Ghost website, Ghost provides a handy tool ghost-cli
, a command line interface tool. So even if your server contains several Ghost websites, you only need the core files once. For this reason, we don't need to backup or copy the Ghost core files at all time. For a new server we only need to install the ghost-cli again then use the ghost-cli to do the dirty work.
Beyond the ghost-cli, a Ghost website relies on a database to store all the content and configuration of the site, and a content folder contains all the files and images you uploaded. These 2 things are the main focus of our migration.
Backup Your Database
Instead of backup the content in the database, we can export the content by using the export tool that is built-in to the admin portal (Labs -> Export your content -> Export). You will get an JSON file contains all data of your website except the files and images.
Regularly backup the content of your website is recommended.
Backup Your Files
Everything you need to copy or download from the server is the content
folder under your ghost website folder on the server. However, in most cases, you only need to download the images
sub-folder under content
. If your server does not provide a file management interface, you can use SSH scp
or sFTP to download the folder. Here to mention the command you could use to pack the folder then download it.
# zip file: zip -r <FileName.zip> <DirPath>
# -r stands for recursive
# current direction: your ghost root
zip -r ./images.zip ./content/images
This will pack everything insider the folder
images
and store them into a zip fileimages.zip
, then you can simply download the content.zip from the server.
Migration
The migration is actually no different than installing a new Ghost website.
Install Again
First, follow this guide (Ghost blog tutorial - Deploy on Server) to install the required environment for Ghost (nginx, nodejs and ghost-cli). Then install a new Ghost as the same meta information as your old website.
Clear Default Database
After finish, login to the admin dashboard, go to Labs -> "Delete all content -> Delete". This will remove several dummy posts and a tag autogenerated by Ghost during installation.
Import JSON
Then import the JSON backup in the same page "Import content -> Import". It might take few minutes if your JSON file is relatively large. It will show an "Import successful with warnings" notice but with some duplicate configuration. Just ignore it for now.
Restore the Files
Now upload the images.zip
file to the new server, under the new website's main folder, you might need the following command to unzip the file:
sudo rm -r ./content/images # delete the new images folder
sudo unzip ./images.zip -d ./content/ # unzip to specified directory
sudo chown -R ghost:ghost /www/ghost/content/images # change the owner to ghost
sudo chmod -R 755 /www/ghost/content/images # change permission if needed
Make sure the sub-directory and files of
content
folder inherit its ownership (ghost) and permission (755). chmod calculator: https://chmod-calculator.com/
Upload Themes
Download your theme from the older server and upload it to the new site (Settings -> Design).
###Final Check
Now you should check whether the site Settings are same as the old one, if not manually change them.
Notice: the
Custom Integration
will not automatically restored, so you need to manually restore the integration setting manually and do some change in the code injection if your theme requires certain configuration such as the search that will use the content API.