How to setup an automated backup of the LXCs backed by ZFS storage, using snapshots.

Objective

Configure scheduled snapshots with expiration date.

Requirements

Ubuntu or Debian server running LXD. Containers must reside on ZFS storage.

Expiration

Set the amount of days you want to keep your snapshots. Here is the example for 10 days:

lxc config set <container-name> snapshots.expiry "10d"

Format

Now let’s set the name format for the snapshots. So that the name of the snapshot would make more sense.

lxc config set <container-name> \
snapshots.pattern 'snapshot-{{creation_date.Format("20060102")}}-%d'

Schedule

Final step is to set the schedule for the automated snapshots. This example will set the time to create the snapshot at 4:15 am, every day. To learn more about scheduling syntax, look here.

lxc config set <container-name> snapshots.schedule "15 04 * * *"

Final

Check to see if your schedule is working correctly. In the Snapshots: section of the info output you will see all of the snapshots, when they were taken and their expiration date.

lxc info <container-name>

 

Enjoy!