Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have two tar files which are basically backups of my /data folder on android. The problem is the permissions and ownership of the files inside latest back-up is messed up. However the permissions in older tar is perfect.

I want a way to read permissions from old.tar and copy over the changes to latest.tar.

I tried extracting files to my own system using -p and --same-owner flag but the ownership changes to root instead of system because my computer doesn't have a user or group called system but my android phone does. I thought I'd extract the files, and write a script which uses stat and grep to read permissions and ownership and sets the permissions and ownerships of the files in latest.tar. But it doesn't seem to work that way. Can anyone give me some help on this issue.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

I'm not sure Tar can do that. It should be possible, though, to untar both backups (to different directories), then use something along the lines of

cd /mnt/oldbackup ; 
find ./ -exec getfacl {} | setfacl /mnt/newbackup/{} 

as the output of getfacl can me used as stdin for setfacl according to the manpage.

share|improve this answer
    
I could do that but on untarring any of the backups, the ownership is lost instantly because the users and groups don't exist on my computer, they exist on my phone. This isn't possible to do on the phone as well, it doesn't have getfacl and setfacl –  Deepak Mittal Oct 23 '11 at 16:32
1  
@dpacmittal Try putting these commands (everything starting with untarring and ending with making a new tarball) in a script and running that script under fakeroot. Fakeroot makes the program think it's root, so it should make tar believe it succeeded in creating files owned by and UID (these changes are only visible to the application running inside fakeroot and are completely forgotten when fakeroot terminates). –  Gilles Oct 24 '11 at 1:10
    
@Gilles Thanks a lot. I ended up manually setting up permissions for the files. I'll remember the instructions next time when my backup goes corrupt. –  Deepak Mittal Oct 27 '11 at 19:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.