Pre-Package Upgrade Azure VM Snapshot
Release package upgrades can sometimes affect data in your Azure instance VM. For example, a failed PostgreSQL upgrade could put the data into an irrecoverable state. To avoid the loss of valuable data, you should take a snapshot (called a VM image version in Azure) of your VM instance before a release package upgrade. Your Cloudhouse representative will advise you on which upgrades might warrant a pre-upgrade snapshot. Taking a snapshot provides an intact backup version of your VM in case you need to revert to an older state. The following guide describes how you can take a snapshot of your Azure instance VM as well as how to revert to a snapshot if there are issues when performing an upgrade.
Dependencies
To take a snapshot of your VM, you’ll need:
-
An image gallery in your Azure resource group. For more information on creating this gallery, see Host Guardian in Azure.
-
A Guardian and Armada data backup to a cloud-hosted environment. For more information, contact your Cloudhouse Representative for assistance.
Take a Snapshot
Taking a snapshot of your VM generates an intact copy of your current instance, including all data and disks, that you can then later use for recovery in the case of a failed upgrade. Before completing the instructions to take a snapshot, contact your Cloudhouse representative to request a graceful shutdown of the VM from within Azure.
To take a snapshot of your VM, run the following command:
Note: Before running the script, insert your own values for the VMID, resourcegroup, name, size, and date attributes.
az sig image-version create \
--resource-group $resourcegroup \
--gallery-name guardian_gallery \
--gallery-image-definition $name \
--gallery-image-version $date \
--location $location \
--virtual-machine $vmid
Snapshots can take between 15-20 minutes to be created in your image gallery.
Once the snapshot is created, start the VM. Once you’ve successfully taken a snapshot, work with your Cloudhouse Representative to perform the upgrade. If successful, the VM is up, and your Cloudhouse Representative will finalize configurations.
Then, you can delete any snapshots that are no longer needed, except for the latest snapshot you took. If an upgrade is unsuccessful, you need to revert your VM to the snapshot you took. For more information, see below.
Revert a VM to an Azure Image Snapshot
If an upgrade is unsuccessful, revert your VM to the snapshot you took that contains your intact data and disks before the upgrade.
To revert your VM snapshot, complete the following:
-
Exit any problematic VMs. This may take more than 5 minutes.
-
Delete old VMs, associated disks, and network interface cards (NIC). Ensure you don’t delete the VM image definition because it stores the snapshot you took.
-
Create a new VM from your most recent snapshot using the following command:
Note: Before running the script, insert your own values for the imageID, resourcegroup, name, location, and size attributes.
imageid=""
resourcegroup=""
## Name can match old VM since it's been deleted
name=""
location="westus" #westus, uksouth
size="Standard_B8ms" #8CPU, 32GB mem
az vm image terms accept --offer "flatcar-container-linux-free" --plan
"stable-gen2" --publisher "kinvolk"
az vm create \
--resource-group $resourcegroup
--name $name --image $imageid \
--enable-agent false \
--specialized \
--plan-name "stable-gen2" \
--plan-publisher "kinvolk" \
--plan-product "flatcar-container-linux-free" \
--location $location --license-type "None" \
--size $size --encryption-at-host "true" \
--public-ip-address "" --nsg-rule "NONE"
Once the new VM is created from your snapshot, your VM has been reverted to the state it was in prior to the upgrade. Now, let your Cloudhouse Representative know the snapshot was successfully reverted. They will then ensure the VM is intact and troubleshoot the upgrade.