6

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.

3 Answers 3

8

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 be used as stdin for setfacl according to the manpage.

3
  • 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 Commented Oct 23, 2011 at 16:32
  • 2
    @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). Commented Oct 24, 2011 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. Commented Oct 27, 2011 at 19:24
2

There is no way to put new meta data into a tar archive, but there is a way to extract just the meta data from a tar archive to the filesystem. Just call:

star -xp -meta < archive.tar

This will not create new files or overwrite file content but just restore the meta data from the archive to the files in the local filesystem. You most likely need -U in addition (see star man page) for "do it even though the file in the archive is not newer than the file on the filesystem".

2

The preferred answer doesn't work anymore (find -exec has changed syntax, and setfacl needs restore= parameter), and the use of find is no longer necessary.

You should do:

cd /mnt/oldbackup 
getfacl -R . >/tmp/permissions
cd /mnt/newbackup
setfacl --restore=/tmp/permissions

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .