My personal website which covers articles about Google Cloud has been growing both in traffic and content. After I wrote my article Google Professional Cloud Security Engineer Certification, my website lit up with traffic and has continued to grow.
In the back of my mind, I wanted to improve the look and feel of my site. This morning I ran into a nice WordPress theme by Anders Norén called Baskerville, so I decided to try his theme and see how everything looks.
If you have ever done serious work with WordPress, you know several things. First, perform regular backups. Second, do not make major changes to a running site, always work on a test site. I have seen new themes destroy a WordPress site requiring hours/days of work to get back online.
This is also a good time to document backing up a Google Cloud Compute Engine VM instance using snapshots, creating a WordPress export, backup the Apache configuration, .htaccess files and dumping the SQL database to a safe location outside of the cloud such as my desktop and Cloud Storage.
Performing the snapshot work requires taking the site offline for a while – maybe 15 minutes if you know what you are doing. I do not recommend performing Google Cloud snapshots on live systems. Snapshots performed this way are not consistent and one day you when you restore from one of these snapshots you will have a corrupted system. I have spent decades writing storage subsystem software, so I know precisely what goes wrong from real-world situations.
Create a Compute Engine VM Snapshot
Go to the Google Cloud Console -> Compute Engine -> VM instances. Select your VM and click the STOP icon. The system will shut down which takes about two minutes. Wait until the instance is completely shut down.
Go to the Google Cloud Console -> Compute Engine -> Snapshots. Click the CREATE SNAPSHOT icon. This pops up the Create a snapshot dialog.
This screenshot shows how I fill out the Name and Description fields. Make these fields informative because in an emergency you do not want to figure out what is what under stress.
Click Create to start the snapshot. Wait for the snapshot to complete. This will take about five minutes.
Go to the Google Cloud Console -> Compute Engine -> VM instances. Select your VM and click the START icon.
My website is a combination of an HTTP Load Balancer and a single Compute Engine VM instance. If I now try to test the website, I will find that it is reporting a 502 error.
Do not panic. This is normal. The load balancer detected that my backend went offline. After a minute or two, everything will be back to normal. If after ten minutes, you are still getting a 502 error, something is wrong. Double check that your Compute Engine VM instance is running and responding to HTTP/HTTPS requests. Debugging this problem is for another article.
Export WordPress Website Content
WordPress has a built-in tool that exports a site’s posts, comments, etc. Just about everything your need except for your media files.
When you click the button below WordPress will create an XML file for you to save to your computer.
This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.
Once you’ve saved the download file, you can use the Import function in another WordPress installation to import the content from this site.
Login to your WordPress Dashboard. Go to Tools -> Export. Select “All Content” and press “Download Export File”. Save to your desktop in a known location. Create a copy of this file on Google Cloud Storage.
Connect to your instance using SSH. In the SSH terminal window, use the mysql program
mysqldump to dump all databases to a backup file.
mysqldump --all-databases -u root -p > mysql-backup-2019-05-12.sql
Download the MySQL backup file to your desktop. I use BitVise which has a nice GUI for remote file access to my instances. BitVise also has a nice SSH Shell window.
You can also use the Google Cloud CLI:
gcloud compute scp ^
--project development ^
--zone us-west1-b ^
Collect Miscellaneous Apache and WordPress files
My WordPress setup is by Bitnami. This means that my custom
.htaccess is located at
/opt/bitnami/apps/wordpress/htdocs/.htaccess. Save this file if you are using one.
Save the file
Be careful with wp-config.php. This file usually contains the keys to your WordPress setup including the login and password to MySQL. Always have a backup of this file and protect access to this file.
Backup your SSL Certificates
I install Let’s Encrypt SSL certificates for my Compute Engine VM instances. This ensures that I can access each individual instance using encryption. These certificates are not used for public website traffic, just administration of the instances.
For Bitnami, the files are located in:
Backup your Critical Apache Files
I backup the entire Apache 2 conf directory
/opt/bitnami/apache2/conf. The critical file is
Backup our Images
WordPress stores media uploads in the
wp-content/uploads directory based from the root of the WordPress content. For my system this is
Download the entire directory.
Now, this brings up an interesting point to consider. My WordPress site is delivering media (images) directory from the Compute Engine instance. An improved implementation is to move all of this content to Google Cloud Storage and serve from there. This will reduce bandwidth on this instance and improve client performance. That will be another day’s work and another article.
In this article, I identified the critical files for a Bitnami WordPress installation on a Google Cloud Compute Engine VM instance. If a disaster occurs, I can rapidly build a new instance, install WordPress and recover the content and media.
The Google Cloud snapshot I created provides the ability to almost instantly recreate a Compute Engine instance with everything exactly as it was at the time of the snapshot.
I also backed up the critical files to my desktop so I can create a new installation. This is the aim of this article as I will now create a new WordPress installation to try the new WordPress theme. Knowing where the critical files are located will make changing the setup straightforward. For example, I will host the new setup on my jhanley.dev domain. I have the critical files so I can create a plan to change the configuration.
Date created: May 12, 2019
Last updated: May 12, 2019
I design software for enterprise-class systems and data centers. My background is 30+ years in storage (SCSI, FC, iSCSI, disk arrays, imaging) virtualization. 20+ years in identity, security, and forensics.
For the past 14+ years, I have been working in the cloud (AWS, Azure, Google, Alibaba, IBM, Oracle) designing hybrid and multi-cloud software solutions. I am an MVP/GDE with several.
Leave a Reply