I'm in the middle of Samba update on a number of servers, each with several shared directories. Users are authenticated against Windows domain AD, so I expect change in local UIDs on Linux boxes. I'd like to know if there is a way to dump ownership of all shared directories so I don't have to set it manually, but to restore it after upgrade.
3 Answers
you could do it by using a script.
1) Dump the directories (the names) in a file.
2) Use find path -type d
(This is to print every directory under the path).
3) Find the common elements and apply ls -lah
A filthy way to do it. It is recommended only if you are desperate :>
Also you may find useful find . -type d -print0 {} \; | xargs ls -lah
-
2Don't use ls, use GNU find's
-printf
option, it gives you full control over the print format. Aug 20, 2010 at 10:43 -
i did it because it's the typical format that you can pass to xargs. in any case, thanks for the info :> Aug 20, 2010 at 11:18
-
Yes, I guess that's the way to go... Combined with weeheavy's usefull awk '{print "chown "$3":"$4,$8}' for restore.– DraskoAug 20, 2010 at 12:30
You can use the getfacl
tool (part of the acl package) to dump and restore both normal unix permissions and acls:
Use getfacl -R
to dump the acls out into a file, and use setfacl --restore=file
to restore them:
--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. If the
input contains flags comments (which define the setuid, setgid, and
sticky bits), setfacl sets those three bits accordingly; otherwise,
it clears them. This option cannot be mixed with other options
except '--test'.
This works even if you don't have acls set - the tool will dump and restore standard unix fs permissions. It will also work if your filesystem doesn't have acl support turned on (it's a non-default mount option for most filesystems still)
Solaris has an advantage here, as it has a nice command called pkgproto
.
But you could use something like
find /home/elao/ -type d | xargs ls -lnd | awk '{print "chown "$3":"$4,$8}'
-
ls -lnd lists files with UID ownership which I want to avoid, because all UIDs will be changed after upgrade due to the idmap backend change. That awk will do the job for restoring with one little change: awk '{print "chown "$3":"$4,$NF}' (on Gentoo filename column is not 8th, but 9th). Thanks for the quick response!– DraskoAug 20, 2010 at 12:35
-