Copy just permissions and ownership from one tar file to another

permissionstar

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.

Best Answer

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.

Related Question