Perform some tasks before starting lxd containers

Hi,

I have some LXD containers running in a host, this host starts every morning, and all the lxd containers started during the boot, I’d like to do following task before certain lxd containers started:

sudo zfs snapshot mypool/database1

possible? for now I do following:

sudo lxc stop cont1
sudo zfs snapshot mypool/database1
sudo lxc start cont1

works, but tedious, any suggestions? Thanks.

Thanks for the info, my use case is a little different, it is a folder in the host that is added to container:

sudo lxc config device add centos6-i386 dataset disk source=/mypool/database/data path=/data

I am taking snapshot of this /mypool/database/data, not the container, I stop the container before zfs snapshot.

after taking up a snapshot, send to another host as backup, works quite well, i don’t need to back up the lxd container itself as it can be easily launch.

Perhaps you could use systemd and a script (see link below)

I think LXD now has tools for backing up pools so you might want to switch to that, but if your way works - it works :man_shrugging:

I think this is what I need, thanks.

Ive just thought you may also want to execute your script before LXD starts, not 100% sure but you could try adding the following to the file

If all you need to do is take a snapshot prior to startup, we have an issue open around improving auto-snapshot timings which will cover this case in the future.

Thanks for pointing that issue, I have inquired there.