5

When modifying permissions on Windows I backup the ACLs to a file first using a commands like:

subinacl /noverbose /output=C:\temp\foldername_redir_permissions_backup_star_star.txt /subdirectories "W:\foldername\*.*"

and...

subinacl /noverbose /output=C:\temp\foldername_redir_permissions_backup.txt /subdirectories "W:\foldername\"

...to back them up.

And then if they need to be restored, a command like...

subinacl /playfile C:\temp\foldername_redir_permissions_backup_star_star.txt

...can be used to restore them.


So can the same thing be done for POSIX permissions on Linux / Unix? And what about ACL extended permissions?

0

1 Answer 1

6

setfacl is designed to accept getfacl output as input. Meaning you can run getfacl, save the output to a file, do your thing, then restore the ACL. The exact procedure can vary depending on your platform. On Linux though:

  # Take a peek at the current ACL
[root@vlp-fuger ~]# getfacl newFile
# file: newFile
# owner: root
# group: root
user::rw-
group::r--
group:provisor:rwx
mask::rwx
other::r--

  # Backup ACL
[root@vlp-fuger ~]# getfacl newFile > newFile.acl

  # Remove the group permission, add another that we'll later want to get rid of
[root@vlp-fuger ~]# setfacl -x g:provisor newFile
[root@vlp-fuger ~]# setfacl -m g:ihtxadm:r-x newFile
[root@vlp-fuger ~]# getfacl newFile
# file: newFile
# owner: root
# group: root
user::rw-
group::r--
group:ihtxadm:r-x
mask::r-x
other::r--

  # Restore ACL to where it was
[root@vlp-fuger ~]# setfacl --restore=newFile.acl

  # Resulting ACL
[root@vlp-fuger ~]# getfacl newFile
# file: newFile
# owner: root
# group: root
user::rw-
group::r--
group:provisor:rwx
mask::rwx
other::r--

You can also use --set-file on the setfacl you use to restore and set it to - if you want to pipe the old ACL in. You can also use getfacl -R to backup the ACL's of entire directory trees.

5
  • WOW! And that'll take the posix too?
    – leeand00
    Jul 6, 2016 at 18:57
  • Can you take the posix separately? There aren't always ACLs...
    – leeand00
    Jul 6, 2016 at 18:58
  • 1
    I'm guessing you mean the standard owner/group permissions? If so then yeah, those are caught as part of backup process. I personally don't know of a way to save those short of modifying your backup file with whatever the file's current permissions are.
    – Bratchley
    Jul 6, 2016 at 19:03
  • The only way I know to get those is to use etckeeper (it's a vcs of your choice with permissions)
    – leeand00
    Jul 6, 2016 at 19:11
  • 1
    The user/group are included in the backup, you'd only have to do something special if you didn't want to clobber changes you've made to those fields and only wanted to reset/restore just the ACL's
    – Bratchley
    Jul 6, 2016 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .