OSX Lion: gnutar restore bad

Discussion in 'Mac OS X Lion (10.7)' started by greno, May 4, 2012.

  1. greno macrumors newbie

    Joined:
    May 3, 2012
    #1
    Hi,
    Today I needed to use gnutar to create a tarball on my Mac-mini w/Lion.

    It tarred up what I wanted and I checked the tarball and all the files and directories showed the proper owner and group.

    Eg:
    Code:
    # gnutar tvzf /tmp/tarball.tgz
    gnutar: Removing leading `/' from member names-rw-r--r-- root/wheel        0 2011-05-25 13:27 Users/.localized
    
    -rwxr-xr-x me/staff        228 2012-05-03 22:48 /Users/._me
    drwxr-xr-x me/staff          0 2012-05-03 22:48 Users/me/
    drwxrwxrwt root/wheel        0 2012-05-03 20:54 Users/Shared/
    -rw-r--r-- root/wheel        0 2011-05-25 13:27 Users/Shared/.localized
    -rwxrwxrwx me/wheel         82 2012-05-03 20:55 /Users/Shared/._SC Info
    drwxrwxrwx me/wheel          0 2012-05-03 20:55 Users/Shared/SC Info/
    -rw------- me/staff       2036 2012-05-04 16:13 Users/me/.bash_history
    -rw------- me/staff          3 2012-05-02 14:39 Users/me/.CFUserTextEncoding
    -rw-r--r-- me/staff         82 2012-05-03 16:38 /Users/me/._.DS_Store
    -rw-r--r-- me/staff      15364 2012-05-03 16:38 Users/me/.DS_Store
    -rw------- me/staff         42 2012-05-03 22:48 Users/me/.lesshst
    drwx------ me/staff          0 2012-05-02 18:30 Users/me/.ssh/
    drwx------ me/staff          0 2012-05-03 23:28 Users/me/.Trash/
    -rwx------ me/staff        228 2012-05-03 23:28 /Users/me/._Desktop
    drwx------ me/staff          0 2012-05-03 23:28 Users/me/Desktop/
    -rwx------ me/staff        228 2012-05-02 21:06 /Users/me/._Documents
    drwx------ me/staff          0 2012-05-02 21:06 Users/me/Documents/
    -rwx------ me/staff        228 2012-05-03 16:37 /Users/me/._Downloads
    drwx------ me/staff          0 2012-05-03 16:37 Users/me/Downloads/
    -rwx------ me/staff        228 2012-05-03 20:55 /Users/me/._Library
    drwx------ me/staff          0 2012-05-03 20:55 Users/me/Library/
    I tried restoring this tarball under /tmp just to check it. And all the files and directories are restored owned by "_unknown _unknown".

    Eg:
    Code:
    # ls -lR
    total 0
    drwxr-xr-x  5 _unknown  _unknown  170 May  2 14:39 Users
    
    ./Users:
    total 0
    -rw-r--r--   1 _unknown  _unknown    0 May 25  2011 .localized
    drwxrwxrwt   4 _unknown  _unknown  136 May  4 17:53 Shared
    drwxr-xr-x+ 16 _unknown  _unknown  544 May  4 17:53 me
    
    ./Users/Shared:
    total 0
    -rw-r--r--  1 _unknown  _unknown   0 May 25  2011 .localized
    drwxrwxrwx@ 2 _unknown  _unknown  68 May  3 20:55 SC Info
    
    ./Users/Shared/SC Info:
    
    ./Users/me:
    total 56
    -rw-------   1 _unknown  _unknown      3 May  2 14:39 .CFUserTextEncoding
    -rw-r--r--@  1 _unknown  _unknown  15364 May  3 16:38 .DS_Store
    drwx------   6 _unknown  _unknown    204 May  4 17:53 .Trash
    -rw-------   1 _unknown  _unknown   2036 May  4 16:13 .bash_history
    -rw-------   1 _unknown  _unknown     42 May  3 22:48 .lesshst
    drwx------   3 _unknown  _unknown    102 May  4 17:53 .ssh
    drwx------+  4 _unknown  _unknown    136 May  4 17:53 Desktop
    drwx------+  6 _unknown  _unknown    204 May  4 17:53 Documents
    drwx------+  8 _unknown  _unknown    272 May  4 17:53 Downloads
    drwx------@ 36 _unknown  _unknown   1224 May  4 17:53 Library
    drwx------+  3 _unknown  _unknown    102 May  4 17:53 Movies
    drwx------+  4 _unknown  _unknown    136 May  4 17:53 Music
    drwx------+  5 _unknown  _unknown    170 May  4 17:53 Pictures
    drwxr-xr-x+  5 _unknown  _unknown    170 May  4 17:53 Public

    # gnutar czf /tmp/tarball.tgz <dir> is how I created it

    # gnutar xzf /tmp/tarball.tgz is how I restored from it.

    Is there some flags I need to give osx gnutar to get it to restore the proper ownership?

    .
     
  2. maflynn Moderator

    maflynn

    Staff Member

    Joined:
    May 3, 2009
    Location:
    Boston
  3. greno thread starter macrumors newbie

    Joined:
    May 3, 2012
    #3
    Because I have a whole set of tools written using gnutar that I brought over to the Mac from my Linux boxes. All I need is for OSX gnutar to actually work as intended and everything is fine. It appears there is some problem with OSX gnutar however.

    .
     
  4. greno, May 4, 2012
    Last edited: May 4, 2012

    greno thread starter macrumors newbie

    Joined:
    May 3, 2012
    #4
    A big problem I can see right away is that OSX gnutar is storing the extended file information inside the archive in "absolute" format. That is WITH the leading '/'. **That is wrong**.

    Eg:
    Code:
    gnutar: Removing leading `/' from member names
    
    -rw-r--r-- root/wheel        0 2011-05-25 13:27 Users/.localized
    -rwxr-xr-x me/staff        228 2012-05-03 22:48 /Users/._me        [B]<<<===[/B]
    drwxr-xr-x me/staff          0 2012-05-03 22:48 Users/me/
    Default behavior of gnutar as you can see from the informational header is to remove all leading '/' unless the archive was specifically created with -P / --absolute-names flag.

    So that is a bug.

    Whatever changes Apple made to gnutar to support its extended file attributes were not done completely correctly.

    So your choices are either create an absolute archive and always use it to restore to the exact same position.
    Code:
    gnutar Pcf tarball.tar /dir /dir /dir  # forward slashes; must be extracted from '/' directory.
    Or always make sure that you archive everything relatively. Even if you are working from / (root) directory.
    Code:
    cd /; gnutar cf tarball.tar  dir dir dir  # no forward slashes
    What you cannot do is create an archive using absolute file references and then extract it to another place.
    Code:
    gnutar cf tarball.tar /dir /dir /dir  # forward slashes; now cannot be extracted to any other location.
    .
     

Share This Page