Can a windows box remote-initiate a zfs snapshot?

Essentially the title is the question. I’d like to do things with a windows box to a zfs / samba share on my DIY nas and then trigger a snapshot on the linux nas/zfs. Any ideas, or is this not possible?

Technically, this should be feasible. But it involves quite a few steps and I’d question the wisdom of automating this. If something goes wrong (and that doesn’t take much!) you could loose all of your data w/o you actually realizing it! Steps include, in random order, writing a script, creating a new user with admin rights, logging in remotely, initiate syncing both NAS’s and creating the actual snapshot.

ssh?

but i actually like the idea of setting up a script (via cron) on the diy nas that checks for a file… and if the filename/contents of the file are valid… it can create a snapshot?

1 Like

I worded that OP very poorly. From a win 10 box, I simply want to trigger a ZFS snapshot on the DIY nas (which is running linux / zfs). From a windows cmd line, maybe? The rest is TMI. Sorry.

While away, I thought of SSH (also as mentioned by @nx2l). I’m familiar with SSH from the interactive terminal, but can you execute a command (with root context) by passing the user password on the cmd line over the wire, or would I have to write a script on the linux side and exec that?

You would log in through SSH (set up properly, meaning using a key, and disallowing root logins), and then sending the command, just like if you were local. By default ZFS requires root to change things, though I believe you can give users certain privileges. I’ve not not messed with that and can’t help.

The real solution that you most likely want is to set up automatic snapshot management, check that it’s working, and then just forget about it.

Here are two excellent tools that basically do the same thing at this point:


If your use case really requires taking a snapshot after you do something, instead of autmatic management with minute by minute snapshots, then you could possibly look into having a script on the NAS check if certain directories have changed recently, and if so produce a snapshot. Be warned, snapshots like this will have to be manually pruned unless you essentially reinvent the above two utilities. And while snapshots are quick and “free”, your performance will decline once you have thousands of the things.

1 Like

Wendell did something similar in this tutorial.

I haven’t tried initiating snapshots from samba, but I’ve seen the settings for samba to expose snapshots directories to windows.

In the pre windows 10 days, if one wanted to launch something on a Linux system, they’d make a shortcut to launch plink.exe with a host and a command.

You can use a special private public key pair, that can do nothing else but do a snapshot. If you need to elevate privileges server side, you can use sudo. In its configs, you can, for example, specify to only allow certain user to launch a specific command as root without requiring a password.


Alternatively, instead of using ssh, you could make some other kind of server and then have another kind of utility communicate with it… but… (and to borrow a meme)
image

I would also recommend SSH.

If the command is a single line, it is no problem just do ssh user@ipaddress command

If the command is multiple lines, then it is possible to pass it to the ssh command as a variable, but it is probably easiest to just exec a shell script on the remote end.

In regards to not passing a password, you always could set up a specific user that has sudo with NOPASSWD, but only has sudo access to zfs commands.

Huh, that’s a really good idea for ZFS/ZPOOL commands that require sudo/root. Hmmm

Great suggestions, “guys”. The auto-snapshot won’t work here, unfortunately.

In this case, process B will stop process A, take a snap, do a number of operations on multiple files (which take an unpredictable amount of time), and the group of files must be in a synced state to be valid. Then it does the changing stuff, and it snaps again at the new finished state. Then process B restarts process A.

Anything between those snaps is invalid, so an auto-snap method would have coherency issues.

I think I’ll look into having sudo configured to allow a couple ZFS commands, or the SSH keyfile would work, or maybe ZFS can allow per-user commands. Sounds like a good rabbit hole to go down, now that I know which hole to jump into.

I’d rather not operate as root routinely,“just because it’s convenient” with the key file. I’d rather have to open an SSH terminal and sudo all the rooty things, to remind me to think “does this really need to be done as root”. I’m trying to burn-in good habits as I get more comfortable with linux.

Thanks for all your help on this, there always seems to be multiple ways to skin a cat on linux.

@Log @TheCakeIsNaOH @risk, all had similar approaches, so I just marked one of them as the solution so as to avoid confusion.

1 Like

Showing ZFS snapshots as their own folders under .zfs/snapshot at the root of the pool, is done by setting snapdir to visible. The folder can then be shared through samba, and is read only of course. This may also possibly interfere with some utilities ability to delete snapshots. I don’t recall having an issue with sanoid, but I haven’t tested it specifically.

zfs set snapdir=visible yourpool

To hide it again, set it to “hidden”.
You can also access snapshots directly using the methods here.

Another useful less known function is using zfs diff to show the differences between snapshots.

1 Like

Ahem, so, when you initiate a ZFS snapshot… in terms of contents of the file system the effect is the same as cutting power to the system.

Can you share more detail about your use case?

Do you have data across multiple filesystems that you need to keep mutually coherent/consistent?

There’s also an option of making ZFS snapshots writeable if there’s any post processing you need to do before you can use the data.