LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 10-30-2016, 08:29 AM   #1
jebert
LQ Newbie
 
Registered: Oct 2016
Posts: 1

Rep: Reputation: Disabled
Unhappy 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.
 
Old 10-31-2016, 02:58 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,681

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
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.
 
Old 11-01-2016, 01:00 PM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
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
 
Old 11-01-2016, 05:44 PM   #4
genogebot
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: Reputation: 20
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.
 
Old 11-01-2016, 07:43 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by jebert View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ownerships/permissions in sub-directories? fadinader Linux - Newbie 31 08-24-2009 12:04 PM
rsync slackware-current ownerships ryanoa Slackware 3 08-30-2006 02:03 AM
rsync Does Not Preserver File Ownership VorlonInfoTech Linux - General 4 10-20-2005 11:19 AM
restoring default device ownerships/permissions under_r_run Linux - Newbie 5 07-27-2005 01:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration