LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Backup with cp -a and rsync -a do not preserver permissions and ownerships (https://www.linuxquestions.org/questions/linux-newbie-8/backup-with-cp-a-and-rsync-a-do-not-preserver-permissions-and-ownerships-4175592527/)

jebert 10-30-2016 08:29 AM

Backup with cp -a and rsync -a do not preserver permissions and ownerships
 
Hi all,

I try to perform a backup of my users home directory on Ubuntu 16.04 server edition, but I am failing to get the files and directories copied while preserving their permissions and ownerships. I guess I am missing something in principle here.

The details:
  • The source dir: /home/myuser
  • the target dir: /media/myuser/myexternalhd
  • The external HD is FAT formatted and was usually in use with Windows, reading and writing work without an issue
  • I tried following commands to perform the backup:
  • 1. sudo cp -a /home/myuser /media/myuser/myexternalhd
  • 2. sudo rsync -a /home/myuser /media/myuser/myexternalhd
  • 3. sudo rsync -gloptrucv /home/myuser /media/myuser/myexternalhd > rsync.log
  • The files were copied as expected, but all files and directories have permissions 777 and myuser:myuser as owner/group, which is definitely not the case for any of the source files or directories
  • The same behaviour I get when I perform a sudo -i beforehand

The question is: What is wrong with my setup? Is it something related with my external drive? Some configuration I need to do? How can I copy everything preserving the permissions and ownership?

Thanks,
j.

michaelk 10-31-2016 02:58 PM

Welcome to LinuxQuestions.

In a nutshell linux file permissions are not compatible with FAT or NTFS. There are several options but if you do not need to use the drive on Windows anymore you could reformat it to a linux filesystem like ext4. You could create an archive using tar for example and save the file to the external drive. Permissions will be preserved and you can still connect the drive to a Windows PC.

szboardstretcher 11-01-2016 01:00 PM

You are also able to specify which user, group and file permissions you want on the whole drive(not individually), in your /etc/fstab file or in a mount command. for user and group 501, and 777 permissions, try:

Code:

mount -t vfat /dev/sda1 /mnt/hdd -o rw,uid=501,gid=501,dmask=0000,fmask=0000

genogebot 11-01-2016 05:44 PM

If you need to use FAT for the backup drive, and you need to preserve Linux permissions, you could create a tar archive of the listed folders and store the archive on the backup drive. It's not ideal, because there's an extra step each way in the archiving/restoring procedure, but given your current setup it may be acceptable.

Edit: oops, sorry I just noticed michaelk already said that :o

jpollard 11-01-2016 07:43 PM

Quote:

Originally Posted by jebert (Post 5624815)
Hi all,

I try to perform a backup of my users home directory on Ubuntu 16.04 server edition, but I am failing to get the files and directories copied while preserving their permissions and ownerships. I guess I am missing something in principle here.

The details:
  • The source dir: /home/myuser
  • the target dir: /media/myuser/myexternalhd
  • The external HD is FAT formatted and was usually in use with Windows, reading and writing work without an issue
  • I tried following commands to perform the backup:
  • 1. sudo cp -a /home/myuser /media/myuser/myexternalhd
  • 2. sudo rsync -a /home/myuser /media/myuser/myexternalhd
  • 3. sudo rsync -gloptrucv /home/myuser /media/myuser/myexternalhd > rsync.log
  • The files were copied as expected, but all files and directories have permissions 777 and myuser:myuser as owner/group, which is definitely not the case for any of the source files or directories
  • The same behaviour I get when I perform a sudo -i beforehand

The question is: What is wrong with my setup? Is it something related with my external drive? Some configuration I need to do? How can I copy everything preserving the permissions and ownership?

Thanks,
j.

The problem is that FAT doesn't have any access mode controls, or user identification. Nearly the same problem when using NTFS as Linux user identification doesn't translate without having mapping tables for the owner and group translation.

If this is strictly a backup operation and the target device will NOT be mounted on a Windows system: Put a linux native filesystem on the destination, then do the rsync/cp. This way the proper access controls, owners, groups (and security labels if any) will be preserved.


All times are GMT -5. The time now is 08:03 AM.