Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pruning LXD snapshots #733

Open
danboid opened this issue Mar 31, 2022 · 2 comments
Open

Support pruning LXD snapshots #733

danboid opened this issue Mar 31, 2022 · 2 comments

Comments

@danboid
Copy link

danboid commented Mar 31, 2022

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.

lxc config set INSTANCE snapshots.pattern "{{ creation_date|date:'2006-01-02_15-04-05' }}"
@danboid
Copy link
Author

danboid commented Mar 31, 2022

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

@danboid
Copy link
Author

danboid commented Mar 31, 2022

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.

https://linuxcontainers.org/lxd/docs/master/backup/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant