The docs of shutil tells me:
Even the higher-level file copying functions (shutil.copy(), shutil.copy2()) can’t copy all file metadata. On POSIX platforms, this means that file owner and group are lost as well as ACLs
How can I keep the file owner and group if I need to copy a file in python?
The process runs on linux as root.
Update: We don't use ACLs. We only need to keep the stuff which is preserved with tools like tar and rsync.
To preserve permissions when files and folders are copied or moved, use the Xcopy.exe utility with the /O or the /X switch. The object's original permissions will be added to inheritable permissions in the new location.
When you copy a protected file to a folder on the same, or a different volume, it inherits the permissions of the target directory. However, when you move a protected file to a different location on the same volume, the file retains its access permission setting as though it is an explicit permission.
The -a or --archive option can be used with the cp command in order to preserve file permissions and ownership. Check the example below where we copy a file one directory to another, while preserving these extra attributes.
Usually, if you copy or drag and drop a shared folder to another location, it inherits the permissions and properties of the drive or folder to which you copy it. To copy shared folders without losing attributes or share permissions, you must use the XCOPY command in Windows.
You perhaps could use os.stat
to get the guid
and uid
like in this answer and then reset the uid
and guid
after coping using os.chown
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With