Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
10-30-2016, 08:29 AM
|
#1
|
LQ Newbie
Registered: Oct 2016
Posts: 1
Rep: 
|
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.
|
|
|
10-31-2016, 02:58 PM
|
#2
|
Moderator
Registered: Aug 2002
Posts: 26,644
|
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.
|
|
|
11-01-2016, 01:00 PM
|
#3
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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
|
|
|
11-01-2016, 05:44 PM
|
#4
|
Member
Registered: Jun 2010
Location: Brisbane, Australia
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 
Last edited by genogebot; 11-01-2016 at 05:49 PM.
|
|
|
11-01-2016, 07:43 PM
|
#5
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Quote:
Originally Posted by jebert
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 11:52 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|