1

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.

  • What is the filesystem type of the second hard drive? If ext2/3/4 does it have any extended attributes set (lsattr /newpath). How is it mounted? – steeldriver May 5 '14 at 23:09
  • File starts on ext4 and goes to fat32. – Michael Jun 29 '14 at 1:05
0

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).

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.