Ubuntu 20.04 zsys/zfs/lxd integration

Ubuntu 20.04 introduces zsys, which periodically takes snapshots of the system. Unfortunately it does not take snapshots of the lxd containers.

Is there a way to integrate lxd snapshots with zsys, so that every few hours a snapshot of selected containers will be taken. (the config files + rootfs)


I am not sure about zsys, @stgraber may be able to offer advice on that specific question.

However you are able to configure automated periodic snapshots of instances like you are asking for.

Take a look snapshot configuration options https://linuxcontainers.org/lxd/docs/master/instances#keyvalue-configuration

If you are using a ZFS storage pool for LXD instances then it will use ZFS snapshots.

snapshots.schedule	string	-	no	-	Cron expression (<minute> <hour> <dom> <month> <dow>)
snapshots.schedule.stopped	bool	false	no	-	Controls whether or not stopped instances are to be snapshoted automatically
snapshots.pattern	string	snap%d	no	-	Pongo2 template string which represents the snapshot name (used for scheduled snapshots and unnamed snapshots)
snapshots.expiry	string	-	no	-	Controls when snapshots are to be deleted (expects expression like 1M 2H 3d 4w 5m 6y)

I would strongly recommend against having an external tool generate ZFS snapshots of LXD datasets.

One significant constraint of ZFS snapshots is that you can only restore the latest snapshot, so if you want to restore an older snapshot, all intermediates are lost.

LXD knows this and handles it by either removing those snapshots (if configured to do so) or letting the user know that they need to do a copy instead. If something external to LXD starts generating snapshots, this logic no longer works and you end up in a situation that’s hard for us to support.

Instead I’d indeed recommend having snapshot scheduling configured in LXD so that you end up with proper LXD snapshots of the instances you care about.