Backup with cp -a and rsync -a do not preserver permissions and ownerships
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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?
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.
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
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146
Rep:
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
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.