LinuxQuestions.org
Visit Jeremy's Blog.
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 05-15-2009, 03:34 PM   #1
z01krh
Member
 
Registered: May 2009
Posts: 34

Rep: Reputation: 0
help with tar not preserving owner


I'm creating a tar via script like this. I am compressing with bzip2.
tar -cjpf /mnt/mybook/cfg.tar.bz2 /home/cfg

mybook is a usb drive on sdb1 formated as fat32. I can't use ntfs since I have the older kernel.... Linux version 2.4.21-15.0.3.EL (bhcompile@daffy.perf.redhat.com) (gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-37)) #1 Tue Jun 29 18:17:52 EDT 2004

My problem is when I extract the tar it errors saying cannot set permissions to 600: Operation not permited. I am creating the tar and restoring it as root.

I have tried restoring with
tar -C /home/cfg -xjpf /mnt/mybook/cfg.tar.bz2 --overwrite
and
tar -xjpf /mnt/mybook/cfg.tar.bz2

Both extract the files but all ownership is root. I only have two users on the system say UserA who has a security of 600 and root. What am I missing that tar is not preserving UserA and making everything root when I extract.

Thanks,
 
Old 05-15-2009, 05:48 PM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,397
Blog Entries: 1

Rep: Reputation: 64
There is no user and access modes in a FAT32 file system !
What you see on a fat32 fs are a fake user and permission.

After extracting the files you have to change the user and modes for what ever you think is correct.
 
Old 05-15-2009, 10:26 PM   #3
z01krh
Member
 
Registered: May 2009
Posts: 34

Original Poster
Rep: Reputation: 0
So would you recommend I format the USB as linux ext3 filesystem?
 
Old 05-16-2009, 01:25 PM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,397
Blog Entries: 1

Rep: Reputation: 64
I am so sorry ! I didn't pay attention to the command itself.
I make an association between the words "fat32" and "ownership" and jumped too fast to the (wrong) conclusion.

What your are doing is right.
It is fine to create a tar file on any kind of media.
Regardless the media type, the tar container has both the data and metadata (owner, access modes, etc).

What is the output of "tar -tjvf /mnt/mybook/cfg.tar.bz2" ? Can you see the original owners and modes ?
Try to extract the files on another place, let say "/tmp/test", as root and using "-p".

Last edited by marozsas; 05-16-2009 at 01:54 PM.
 
Old 05-16-2009, 08:00 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And as for root being unable to do something ... do you
have SELinux enabled?
 
Old 05-16-2009, 10:23 PM   #6
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
What command did you use to create the tar file?
 
Old 05-17-2009, 12:51 PM   #7
z01krh
Member
 
Registered: May 2009
Posts: 34

Original Poster
Rep: Reputation: 0
When I run tar -tjvf /mnt/mybook/cfg.tar.bz2 it appears to be correct. It stored all read/write properties and ownwer and permissions.

For example
-rw-rw-r-- UserA/user 198 2006-01-23 10:43:08 home/cfg/gatxrpt.cfg

The command I am using to create the tar is
tar -cjpf /mnt/mybook/cfg.tar.bz2 /home/cfg

When I extract to /tmp using "tar -C /tmp -xjpvf cfg.tar.bz2" It appears to have worked. All file permissions were there. Yet when I do the same thing on the fat 32 drive no permissoins were saved. So I guess extracting to the Fat 32 filesystem may be the culprit.. I guess I will have to change my script extact to tmp then cp -frdp to get the files to the correct folder with correct permissions. Kind of a pain but at least I can script that out. Thanks for all your suggestions.
 
Old 05-17-2009, 02:16 PM   #8
NeddySeagoon
Gentoo support team
 
Registered: May 2009
Location: 56N 3W
Distribution: Gentoo
Posts: 178

Rep: Reputation: 40
z01krh,

When you untar on a fat32 volume, permissions and ownership cannot be preserved as fat32 does not support those features of *NIX filesystems/

If you really want to do what you are trying to do, you need a *NIX filesystem on the USB drive. Do not use a journaled filesystem as USB does not support DMA access and the journal accesses will slow things down. ext2 is a good choice.
 
Old 05-17-2009, 06:33 PM   #9
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,397
Blog Entries: 1

Rep: Reputation: 64
oh yes, if you extract the tar on a fat32 it really loose the owner and modes.
Extracting the files to /tmp and after that copying to the correct folder will work, but instead, you can extract the files to the right place in one single operation. There is no need to use an intermediate place unless you do some kind of filtering or any other operation on the files.

The best approach is to change to parent directory of the folder you want to create (or restore) a backup. As far I understand it is cfg on /home, right ?

# creating the tar file
Code:
cd /home
tar -cjf /mnt/mybook/cfg.tar.bz2 cfg
# extracting the files from the tar file
Code:
cd /home
tar -xpjf /mnt/mybook/cfg.tar.bz2
so, there is no need to use an intermediate area.

Last edited by marozsas; 05-17-2009 at 06:34 PM.
 
Old 05-18-2009, 12:02 AM   #10
z01krh
Member
 
Registered: May 2009
Posts: 34

Original Poster
Rep: Reputation: 0
The point of the USB is storage is it will take daily backups run via cron. In the even of a failure I use Clonezilla to restore my image then all I have to do is restore the last backup from the USB drive. I don't have the space on the host system to hold the backup. Nor is it a good idea. After all the point of a backup is in case the host fails. I plan on writing a script to loop through the key folders and export them by folder name to the USB drive. Tar with bzip2 seems to be the best way for compression. I'm not to worried about speed since it will run after hours via cron which is why I am using bzip2 over gzip.


something of the effect of this

export backup_date='date +%F'

if [[ ! -d /mnt/mybook/$backup-date ]];then
mkdir -p /mnt/mybook/$backup-date
fi

for DIR in `find /home `
do
cd $DIR
tar -cpjf /mnt/mybook/$Backup-date/$DIR.tar.bz2
done

Then reverse it for the restore. You get the point. Since the drives are not used in production yet I may take Neddy's point and format them as linux ext2. Just to be on the safe side and not risk loosing my key owners and permissions.
 
Old 05-18-2009, 08:47 AM   #11
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,397
Blog Entries: 1

Rep: Reputation: 64
I'm sorry but I didn't get the point: Why do you need to restore the backup on usb disk ?
For sure it is fine to create a tar file on usb disk, there is no problem with this.

On restore you just need to extract the files directly on their original place, or am I missing something ?

For sure, as Neddy told us, you can format your usb disk as ext2, but my point is this is unnecessary. You can restore files directly to their original place. Do you known you can select just a few files to extract, you don't need to restore the whole thing ? Something like "cd /home; tar -xjvf /mnt/mybook/cfg.tar.bz2 cfg/folder-a/file1 cfg/folder-b/file2 cfg/folder-c" ...
 
Old 05-18-2009, 09:49 AM   #12
z01krh
Member
 
Registered: May 2009
Posts: 34

Original Poster
Rep: Reputation: 0
marozsas I don't need to restore it to the usb. The problem was I need the usb to hold it. I plan on extacting it from the USB to the host system. I will attempt this again today and post the results later. Also I plan on restoring the whole tar file since this is in the event the system completely fails and I loose all data. Now if a user deletes a file they needed off the host then I can just manually restore that rather than all the data.
 
Old 05-18-2009, 10:14 AM   #13
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,397
Blog Entries: 1

Rep: Reputation: 64
Question

Hi z01krh !

ok, I was confused because you told us you are in fact extracting to a fat32:
Quote:
Originally Posted by z01krh View Post
Yet when I do the same thing on the fat 32 drive no permissoins were saved. So I guess extracting to the Fat 32 filesystem may be the culprit.
and now you clarify:
Quote:
Originally Posted by z01krh View Post
... I don't need to restore it to the usb.
so, I was lost about what you really are doing....

Anyway, if you don't need to restore it to a fat32 filesystem, just to store the tar file on a fat32 filesystem, it is ok. You should not have any problem with this. You don't need to format your usb disk as ext2, as fat32 it is ok.

But this brings us back to the original situation you described in your first post, and I am not sure if your restore problem with owner/modes was solved or not.

????

Last edited by marozsas; 05-18-2009 at 10:49 AM.
 
Old 05-18-2009, 02:19 PM   #14
NeddySeagoon
Gentoo support team
 
Registered: May 2009
Location: 56N 3W
Distribution: Gentoo
Posts: 178

Rep: Reputation: 40
z01krh,

The permissions and ownerships are properly preserved inside the tarball regardless of the filesystem the tarball is stored on. They are lost on untarring to any filesystem that does not support *NIX permissions. This has no effect on the content of the tarball.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 03:48 AM
Owner of a directory different than file owner problems Guardian-Mage Linux - Server 4 04-24-2009 11:26 AM
rsync not preserving owner and group graziano1968 Linux - Server 6 09-10-2008 08:52 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 03:53 AM


All times are GMT -5. The time now is 04:44 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration