Recently we’ve introduced the ability to export Compute instance snapshots, which can in turn be either downloaded locally as an additional backup measure or used to create custom templates. In this post we will give you a quick overview of how to do it using the exo CLI.

Creating a Snapshot

You can create a snapshot either from the Exoscale portal or using the exo CLI:

$ exo vm list
┼──────────────────────────────────────┼───────┼──────┼──────────┼─────────┼──────────────┼
│                  ID                  │  NAME │ SIZE │   ZONE   │  STATE  │  IP ADDRESS  │
┼──────────────────────────────────────┼───────┼──────┼──────────┼─────────┼──────────────┼
│ cd3ab71f-6843-4c1b-9632-bf6f75fc9831 │ test  │ Tiny │ at-vie-1 │ Running │ 185.150.8.79 │
┼──────────────────────────────────────┼───────┼──────┼──────────┼─────────┼──────────────┼

$ exo vm snapshot create cd3ab71f-6843-4c1b-9632-bf6f75fc9831
Creating snapshot of "test"... success
┼──────────┼──────────────────────────────────────┼
│ SNAPSHOT │                                      │
┼──────────┼──────────────────────────────────────┼
│ ID       │ 945fed4a-18d0-4551-951d-ee25467c3b37 │
│ Date     │ 2020-05-13T12:33:15+0200             │
│ Instance │ test                                 │
│ State    │ BackedUp                             │
│ Size     │ 10 GiB                               │
┼──────────┼──────────────────────────────────────┼

Exporting a Snapshot

Once the snapshot is created it can also be exported. The export process will create a link that can be used to download the snapshot file:

$ exo vm snapshot export 945fed4a-18d0-4551-951d-ee25467c3b37
exporting snapshot "945fed4a-18d0-4551-951d-ee25467c3b37"................ success
┼──────────┼──────────────────────────────────────────────────────────────────────┼
│ URL      │ https://exported-snapshots-at-vie-1-prod.sos-at-vie-1.exo.io/980a... │
│ Checksum │ cc799b9851a3757318650bb543ed48cc                                     │
┼──────────┼──────────────────────────────────────────────────────────────────────┼

The export process can take quite some time, so please be patient; once you have the URL you can download the snapshot. Note that the URL returned by this operation is only valid for 6 hours: passed this time, you will have to export the snapshot again the retrieve a fresh URL (subsequent export operations are virtually instantaneous).

Registering a Snapshot as a Template

Before moving on to the template registration part, we need to look up the boot mode of the Compute instance template the snapshot originates from, as we’ll need to specify it during registration to ensure the Compute instances that will use it can boot properly.

If you are using Linux and Bash you can use the following script to get the boot mode:

SNAPSHOT_ID=945fed4a-18d0-4551-951d-ee25467c3b37
TEMPLATE_ID=$(exo vm snapshot show --output-template {{.TemplateID}} ${SNAPSHOT_ID})
BOOTMODE=$(exo vm template show --output-template {{.BootMode}} ${TEMPLATE_ID})

Or in Powershell:

$SNAPSHOT_ID={945fed4a-18d0-4551-951d-ee25467c3b37}
$TEMPLATE_ID=exo vm snapshot show --output-template {{.TemplateID}} ${SNAPSHOT_ID}
$BOOTMODE=exo vm template show --output-template {{.BootMode}} ${TEMPLATE_ID}

This will store the boot mode in the $BOOTMODE variable which we will use later.

Now that you have the details of the exported snapshot you can either download it, or use it to register a custom template on Exoscale to reuse it as a basis for new Compute instances deployments.

To register it as a custom template you simply pass the URL and checksum above to the exo vm template register command:

$ exo vm template register \
    --name test \
    --boot-mode $BOOTMODE \
    --url "https://exported-snapshots-at-vie-1-prod.sos-at-vie-1.exo.io/980a..." \
    --username ubuntu \
    --zone at-vie-1 \
    --checksum cc799b9851a3757318650bb543ed48cc \
    --description "My test template"
Registering the template............................................................... success
┼───────────────┼──────────────────────────────────────┼
│   TEMPLATE    │                                      │
┼───────────────┼──────────────────────────────────────┼
│ ID            │ 06b97217-3820-4fcc-91af-f51aff68823c │
│ Name          │ test                                 │
│ OS Type       │ Other (64-bit)                       │
│ Creation Date │ 2020-05-13T10:37:48Z                 │
│ Zone          │ at-vie-1                             │
│ Disk Size     │ 10 GiB                               │
│ Username      │ ubuntu                               │
│ Password?     │ true                                 │
┼───────────────┼──────────────────────────────────────┼

Alternatively, the exo vm template register --from-snapshot <ID of a snapshot> command performs the snapshot export operation and then registers the template using the exported snapshot file URL/checksum directly.

Finally, you can of course start an instance from the template:

$ exo vm create test --template 06b97217-3820-4fcc-91af-f51aff68823c
Creating private SSH key
Deploying "test" ⠙                                                                                done
...

That’s it! You can now use a single Exoscale instance as a golden master for your other instances.