zfs snapshot from inside of container

michabbs

Active Member
May 5, 2020
138
20
38
I want to send my database backup to a cloud. Generally in order to get consistent backup - the filesystem should be snapshotted. The "normal" procedure looks so:

- snapshot zfs dataset
- rcolne
- destroy snapshot

But.. it is impossible to create snapshot while beeing inside of lxc container. The above procedure works very well directly on the pve node. On the other hand - it seems to be a bad idea to do it directly on the node... :-(

I noticed that I have access to .zfs/snapshot folder inside the container - so it is possible to read the snapshotted dataset (good). But I see no way to create and destroy the snapshot (bad). Any idea how to achieve it in the container?
 
Hi,
I want to send my database backup to a cloud. Generally in order to get consistent backup - the filesystem should be snapshotted. The "normal" procedure looks so:

- snapshot zfs dataset
- rcolne
- destroy snapshot

But.. it is impossible to create snapshot while beeing inside of lxc container. The above procedure works very well directly on the pve node.
If the dataset lives on the host, it should be operated from the host.

On the other hand - it seems to be a bad idea to do it directly on the node... :-(
Why?

I noticed that I have access to .zfs/snapshot folder inside the container - so it is possible to read the snapshotted dataset (good). But I see no way to create and destroy the snapshot (bad). Any idea how to achieve it in the container?
I'd argue that it's part of the point of containerization, that the container should only see the dataset from the inside, not the outside.
 
Because if I migrate CT to another node - the backup wont work anymore.
While not ideal, workarounds could be one of the following:
  • Set up a script on all nodes, which checks if the container is on the local node and does nothing otherwise.
  • Determine which node the container is on and use ssh for the rest of the commands. This requires that both the node with the script and node with the container are online, so that's a downside.
 
Working solution:

- I (ab)used cv4pve-autosnap - I installed it inside the CT and this way the container is able to "snapshot itself". (Of course it might be done via PVE API, but cv4pve-autosnap just does it and even automatically deletes old snapshot.)
- After snapshotting my script simply finds the latest available .zfs/snapshot subfolder and reads data from there. That's it. :-)
 
  • Like
Reactions: fiona