Ubuntu – Copying Folder while Preserving Permissions/Ownership Error: operation not permitted

MySQLownershippermissions

I am trying to copy a folder while preserving ownership. When I use the command:

sudo cp -R -p /var/lib/mysql /newpath

the files copy but the ownership changes (my username becomes the owner on the new files) and I get an error message saying that cp: failed to preserve ownership for '/newpath/subdirectory' : Operation not permitted for each subdirectory and file in the copied folder. Trying to switch back ownership on the copied files produces the same error (with chown in the place of cp).

sudo chown -R username:group /newpath

I am trying to copy a mysql data directory folder to my second hard drive in such a way that I can then use it as the database directory for the mysql server (username mysql) with webmin.

Best Answer

FAT32 (or any FAT-type filesystem for that matter) does not support permissions. Any file copied to a FAT filesystem will appear with default owner/group/mode attributes, depending on how the filesystem was mounted.

If you need to preserve these attributes, use a different filesystem. Most (if not all) Unix filesystems (ext*, ReiserFS, btrfs and a bunch of others) supported by Linux will work, so will NTFS to an extent (not strictly a Unix filesystem but designed with a certain degree of Unix compatibility in mind).

Related Question