Starting today, you can customize how long we retain snapshots of your volumes. You can keep them for 1 day all the way up to 60 days. The default continues to be 5 days.
This helps you tune your volume snapshot availability based on your own retention needs.
Setting the snapshot retention
Set the snapshot retention for your volumes when creating or updating volumes with the Machines API or flyctl. For example, this API call will create a volume that retains snapshots for 10 days:
curl -i -X POST \
-H "Authorization: Bearer ${FLY_API_TOKEN}" -H "Content-Type: application/json" \
"https://api.machines.dev/v1/apps/my-app-name/volumes" \
-d '{
"name": "my_app_vol",
"region": "ord",
"size_gb": 10,
"snapshot_retention": 10
}'
This API call will update an existing volume to have a snapshot retention of 14 days:
curl -i -X PUT \
-H "Authorization: Bearer ${FLY_API_TOKEN}" -H "Content-Type: application/json" \
"https://api.machines.dev/v1/apps/my-app-name/volumes/vol_340088w293z35lp4" \
-d '{
"snapshot_retention": 14
}'
flyctl can do this with the --snapshot-retention
flag when creating or updating a volume. For example:
fly volume create --snapshot-retention 10 my_app_vol
fly volume update --snapshot-retention 14 vol_340088w293z35lp4
You can also set your desired snapshot retention on mounts in your fly.toml. Any volumes that fly deploy
creates will have the configured snapshot retention. For example, this will ensure all volumes created by fly deploy
will have snapshot retention set to 14 days:
[mounts]
source = "myapp_data"
destination = "/data"
snapshot_retention = 14
This require flyctl v0.2.48 or later.
How we built this
Volumes are LVM Logical Volumes under the hood. A volume snapshot is created using the LVM create snapshot feature. We compress the snapshot and upload it to s3 compatible storage.
Before today, we had a single lifecycle rule on our s3 compatible storage that expired all objects after 5 days, which is why every volume snapshot was retained for 5 days. That was simple and worked great. The tradeoff is all objects in the bucket get the same retention.
Now we add a tag to each object we upload that specifies how long to keep the object. For example, we’ll set a retention=10days
tag on snapshot objects when the volume has snapshot retention set to 10 days.
We wrote new lifecycle rules, one for every tag value 1–60days, to implement the configurable retention periods. They look like this:
{
"Rules": [{
"ID": "expire-after-01-days",
"Status": "Enabled",
"Filter": {
"Tag": {
"Key": "retention",
"Value": "01days"
}
},
"Expiration": {
"Days": 1
}
},
... other rules omitted for brevity ...
{
"ID": "expire-after-60-days",
"Status": "Enabled",
"Filter": {
"Tag": {
"Key": "retention",
"Value": "60days"
}
},
"Expiration": {
"Days": 60
}
}]
}
And that’s it! Our s3 compatible storage will automatically expire objects based on the configured snapshot retention on the volume.
Caveats
We do support updating the snapshot retention for volumes, but we don’t retroactively change the retention on any existing snapshots. New snapshots created after the volume is updated will use the new retention value.
We’re working on exposing the retention of individual snapshots in the Machines API and flyctl. Stay tuned for updates on that!
We automatically create a new snapshot for each volume every day. You can create snapshots anytime using the Create an on-demand volume snapshot api, or fly volume snapshots create <volume_id>
.
We are figuring out billing for volume snapshots. We’ll give you advanced notice and plenty of time to make changes to snapshot retention before we turn on billing.