1

I am trying to backup a directory to cloud storage, but since most solutions do not natively support specifying the user/group of a file I would like to save the user/group to a file and backup that file so that they can be restored if/when the backup is needed.

getfacl/setfacl can be used for this for rwx permissions (as described here) but is there a similar tool for users/groups?

  • Utterly no idea why this question was downvoted. It‘s valid and addresses a very real world issue of non-native (aka: “cloud”) storage systems not storing some basic/necessary metadata. – JakeGould Sep 3 at 18:23
2

The answer is in the resources you linked to.

From here:

getfacl -R / >permissions.facl
setfacl --restore=permissions.facl

(In your case it will be /some/dir instead of /).

And then man 1 setfacl [emphasis mine]:

--restore=file
Restore a permission backup created by getfacl -R or similar. All permissions of a complete directory subtree are restored using this mechanism. If the input contains owner comments or group comments, setfacl attempts to restore the owner and owning group. […]

Note you need CAP_CHOWN capability to change ownership. This applies to any method.


If you need to restore only users+groups (without touching ACLs) from permissions.facl, there are at least two options:

  1. Parse the file and dynamically build a script containing many chmod lines. I won't build a parser here. Note file names (i.e. # file: entries) may contain translated troublesome/unprintable characters and you need to translate them back.
  2. Possible workaround (untested!):

    • save current metadata with getfacl -R to current.facl;
    • remove all owner comments and group comments from current.facl;
    • restore metadata from permissions.facl;
    • restore metadata from current.facl.

    Restoring from current.facl will revert everything that restoring from permissions.facl did, except users+groups. In the end only users+groups will depend on permissions.facl.

  • Ah I assumed the comments were just comments - thanks – dippynark Sep 3 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.