I was restoring a root partition based on a tar backup from system-rescue-cd. It went ok except the uid/gid mappings on the system-rescue-cd disk did not match the ones on this debian system that I was restoring. This broke a number of packages and setuid/setgid permissions. For example, the atjobs in spool was owned by bin instead of daemon, and the man pages weren't owned by the man uid.

How do I detect and recreate just the permissions from the tarball without starting the restore process over?

I found I could detect the uid/gid differences via "(cd / ; tar jdpf /my/backup.tar.bz2)" but now I have to filter out the "Uid differs" and "Gid differs" output and it doesn't include the directories in the output, just the files.

If disk space wasn't an issue, maybe rsync could do this, if I untar to another disk?

I do not want to extract files again as contents have changed on the system. I just want to adjust the permissions.

  • Long ago, you could run a command on a RedHat box that would check all the important permissions and set them according to the FSSTAND. I remember doing it. Dunno if Debian has something similar. I believe the dpkg command may have an option, but that would be package by package.
    – Timbo
    Nov 18, 2014 at 18:46
  • and MacOSX had a Check and Fix Permissions program in 10.0-10.3 that you could run after each OS upgrade.
    – dols
    Nov 19, 2014 at 0:05
  • btw, to avoid getting into this mess next time use --numeric-owner option when extracting to make tar use numeric uid/gid (see this question for details). Nov 23, 2014 at 19:16

1 Answer 1


You can get a list of all the chown commands to issue like this:

tar --numeric-owner -tvjf backup.tar.bz2 | 
perl -e 'while (<STDIN>) { s|/|:|;  @t = split(" ");  print "chown $t[1] \x27$t[5]\x27\n";  }' |
tee /tmp/chown_cmds

Output will be like:

chown 0:119 './var/cache/jockey/driverdb-OpenPrintingDriverDB.cache'
chown 0:119 './var/cache/jockey/check'
chown 0:7 './var/cache/cups/'
chown 7:7 './var/cache/cups/ppds.dat'

Have a look at /tmp/chown_cmds, make sure it looks good and run this to restore all the uids/gids from the backup:

$ cd / ; sudo bash /tmp/chown_cmds

You could filter out files owned by root to make the list way shorter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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