Forem Creators and Builders 🌱

Andrew Brown
Andrew Brown

Posted on • Updated on

How to Backup a Forem Server's OS Image and Virtual Drive on AWS

Forem uses Fedora CoreOS to allow you save the OS Configuration state of your VM.
This is great at the OS level, but what happens if let us say a junior comes in mistaken terminates our instance. Will lose everything.

Also what happens if we wanted to run a second server in another multiple availability zones to ensure if one datacenter goes out that our app remains running?

This is where we want to take advantage of Amazon Linux Images (AMIs) Elastic Block Store (EBS) Snapshot and Launch Templates.

What is EBS?

EBS is virtual harddrive that is attached to your EC2 instance. This is where your app, your database and all your data resides.

We can create a snapshot of the EBS volume (which is stored in S3) and will be redundantly stored across multiple datacenters so its highly durable.

But we don't need to do this because when we create an Amazon Machine Image (AMI) it will also create an EBS snapshot

What is AMI?

AMI is a machine image of the OS configuration and and an EBS snapshot. When we have an AMI we can easily launch another virtual machine with the exact OS configuration and data. We will still have to configure our virtual networking like VPCs, Security Groups and etc.

Before we create our AMI lets first create a Launch Template that will store all our cloud networking configuration.

Creating a Launch Template

Lets create a Launch template from our running EC2 instance

Alt Text

Give your launch template a name and description

Alt Text

Observe that you have the current Instance Size and Type

Alt Text

Create your Launch Template

Alt Text

Creating an AMI

We have our Launch Template, but if we were to terminate our instance and launch a new EC2 server it would cloud our Forem installation or SSM agent we installed because it would just be the base image.

So we need to create a new AMI and then add a layer.

So go back to your EC2 instance and create an Image

Alt Text

When you create Images most Cloud Service Providers recommend you stop your instance before doing so, but I rarely do this in practice with AWS. On Azure they will make you stop the instance before hand.

Name your image and create. I find it best to put the ISO date in there followed by an incremental version when you are manually creating AMIs.

Alt Text

At the time of writing this article the default size of Forem uses to provision the EBS volume is 100 GB and that really big. EBS snapshots is a common hidden cost so if you are early days with your Forem Server here you can change the size down to 30 GB.
Alt Text

Navigate over to AMI in the left hand column and wait for the AMI to finish creating. It takes a few minutes.

Sometimes you need to hit the refresh button in the AWS Console.

Alt Text

Updating our Launch Template

Now that we have a new AMI we will go to our Launch Templates and create a new version

Alt Text

You can go ahead and search your AMI

Alt Text

If you resize your EBS volume size you may need to accept the prompt

Alt Text

Go ahead and create a new version

Alt Text

Launch a new VM

We can now launch ourselves a new VM to replace our old one. So launch a new instance from our Launch Template

Alt Text

Scroll to the bottom and Launch the template

Alt Text

Make your way over to EC2, just so we don't get confused between the old and new I am going to rename the Instance while its in the initializing state

Alt Text

While I wait for this new instance I am going to terminate the old one. This will cause downtime but I don't have anyone on my platform right now so its alright for me.

Best practice would be verifying the new server is working before terminating the old one.
Alt Text

I get a warning about termination because it will delete the old EBS volume.

Alt Text

Our new instance is running, we need to take the Public IP address and update our routes to point to the new server.

Alt Text

I use Route53 so I just updated my record with the new IP address
Alt Text

Considerations

Whenever you make changes, even though Fedora CoreOS will version OS configuration changes, you will want to periodically create AMIs and managed the versions in an EC2 Launch Template.

You will notice that there is risk of downtime because we have to swap out the IP Address. We can use a Elastic Load Balancer or an Elastic IP (static IP) to mitigate that issue.

Top comments (0)