Open danboid opened 2 years ago
Some of my notes on using LXD with ZFS:
Configure lxd's zfs.clone_copy option
Before we start creating containers, each of which will be given its own ZFS dataset within the pool, we should configure how LXD handles the creation of new containers. Setting zfs.clone_copy
to false will perform a full copy of the dataset rather than creating a new dataset that is a zfs snapshot of the difference between the chosen base image for the container and your new container:
$ lxc storage set default zfs.clone_copy false
Disabling this option uses a little more disk space for each new container but makes more sense if you are making use of per container ZFS snapshots via LXD and to improve ease of data recovery.
Creating ZFS snapshots with LXD
LXD supports creating ZFS snapshots of instances. You need to configure the LXD snapshots.schedule, snapshots.expiry and the snapshots.pattern options. For Hermes, we want to create a snapshot twice a day and retain 6 months of snapshots:
$ lxc config set hermes snapshots.schedule "0 */12 * * *"
$ lxc config set hermes snapshots.expiry "3m"
$ lxc config set hermes snapshots.pattern "{{ creation_date|date:'2006-01-02_15-04-05' }}"
If you don't configure snapshots.pattern, LXD defaults to naming the snapshots @snapshot-snap0, without the time and date.
snapshots.schedule
uses cron notation to define its values whilst snapshots.pattern
uses Pongo2.
Note that by default, LXD won't let you restore a ZFS snapshot of a container other than the very latest snapshot unless volume.zfs.remove_snapshots is enabled:
$ lxc storage set default volume.zfs.remove_snapshots true
lxd recover
allows users to create/restore a container from a regular ZFS dataset without any of the LXD config, db and metadata. lxd recover
is hence what you'd have to use to import a pruned dataset back into LXD.
I'm using syncoid to backup some some ZFS based containers from my LXD server onto another remote pool and I'd like to be able to use sanoid to prune the old snapshots but it doesn't look like sanoid can prune datasets whose snapshots weren't created by itself currently.
LXD doesn't timestamp the names of its snapshots by default but its easy enough to make it do that as documented at the bottom of the Instances page by configuring
snapshots.pattern
and thats the format of snapshots I'd like to be able to prune with sanoid.