I'd like to clone all the ZFS ACLs from one file to another.
With POSIX ACLs this can be done by piping the output of getfacl
to setfacl
.
Is there an easy and quick way to do this with the NFSv4 style ACLs in ZFS? I know I can read off the output of ls -lV
and then enter it as part of a chmod
, but I can't seem to find a functional equivalent to the POSIX way of copying ACLs.
Instead of using
ls -lV
you can usels -lv
which can be fed in to a script to convert it to a sequence ofchmod
commands to duplicate the ACLs.E.g. if the ACl looks like this:
It should be turned in to the following sequence of
chmod
commands:I recently found myself in a situation where a script like the one described above would have been useful, so here's a little Bash script I made (can also be sourced to the shell and run as a function) to print the list of chmod commands necessary to copy the ZFS ACLs from one file to another:
Here are a couple example usages and their output for file1 from above:
If we like, we can even evaluate these chmods directly, if both files are accessible on this host and we wish to copy the ACLs from file1 to file2 immediately:
I ran into this same issue. My code is here:
https://gist.github.com/1021032
Works like a charm for me. Hope it's handy if anybody else out there ever runs into this problem.
Taking what Martin suggests and applying a bit of perl you might get something like:
try it before uncommenting the system(@out) lines.
Annoyingly, this doesn't seem to be properly exposed at the shell level. In C, there are functions
acl_get(3SEC)
andacl_set(3SEC)
which can be used to take the ACL from one file and apply it to another (among other options, obviously). They will also, usefully, translate an ACL from POSIX-draft to NFSv4 type; this is what system commands likemv
andcp
use.I wrote, at one time, a command to copy an acl from a source to a destination file using this technique, but I presently cannot find the source code. Should I find it, I'll append it to this answer.