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

Sanoid/Syncoid completly fails in Solaris due to zfs get call - fix included. #777

Open
brendon0 opened this issue Oct 12, 2022 · 2 comments

Comments

@brendon0
Copy link

In Solaris the "zfs get" function call fails as there is no "-t" option in Solaris, however this exists in Linux / OpenZFS

This is referenced in line 808 of the 2.1.0 Sanoid code:

open FH, "$zfs get -Hrpt snapshot creation |";

Outputs:
root@SolarisZFS:/opt/csw/bin# zfs get -Hrpt snapshot creation
invalid option 't'
For more info, run: zfs help get

This however works fine in Linux as the "zfs get" function does have a "-t" option.

Outputs:
root@ubuntuzfs:/etc/sanoid# zfs get -Hrpt snapshot creation
flash@test creation 1665337414 -
flash/smb/documents@autosnap_2022-10-09_17:45:27_monthly creation 1665337527 -
flash/smb/documents@autosnap_2022-10-09_17:45:27_daily creation 1665337527 -

On further investigation, the "zfs get -t snapshot" is basically just doing a "zfs get all" and filtering by snapshots.

An alternative method of doing this is using grep and filtering by the "@" symbol. This will make this function
call compatible with both Linux and Solaris with a single line of code change.

"zfs get -Hrp creation | grep @"

Output:
root@SolarisZFS:/opt/csw/bin# zfs get -Hrp creation | grep @
flash/smb/documents@autosnap_2022-10-10_17:06:42_monthly creation 1665436002 -
flash/smb/documents@autosnap_2022-10-10_17:06:42_daily creation 1665436002 -

I am proposing the following code change to ensure compatibility with both Solaris and Linux/OpenZFS derivatives of ZFS.
Change line 808 of the code to the following:

open FH, "$zfs get -Hrp creation | grep @ |";

This has been tested as working in both my Solaris and Linux installs.

Also I believe this fix will work in Syncoid as well as it also uses the "-t" filter however I have not had time to test it.

@jimsalterjrs
Copy link
Owner

I appreciate the fix, but I'm not happy with piping through grep. This introduces new and exciting ways for things to fail on different distros when grep may or may not be in the PATH, etc.

If we're going to filter that way, I'd strongly prefer just getting -Hrp creation, then in Perl just destroying elements that don't contain an @. That way we don't cause further headaches down the road. This can be accomplished with a simple check along the lines of if ($str =~ /\@/) { do stuff; } or the inverse.

@brendon0
Copy link
Author

brendon0 commented Oct 12, 2022 via email

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

2 participants