using pax command for archive & restore

Karl Vogel vogelke+unix at
Mon Apr 8 00:10:29 UTC 2013

>> On Thu, 04 Apr 2013 21:07:46 -0400, 
>> Joe <fbsd8 at> said:

J> I archive using the pax command like this
J>   pax -wzXt -x cpio -f ${archive_path_file} ${ip_path_file} ${ip_path_dir}

J> and restore
J>   pax -rz -pe -f ${archive_path_file}

J> and it restores the contents back to the same location it came from
J> which is what I want.  Now I would like to restore that archive file to
J> a different directory.  This has to be simple, but I can't see the trees
J> because the forest is in the way.  What am I missing here?

   I use pax all the time, and it's much easier to do what you want if you
   use it from a relative directory as part of a pipeline.  When creating
   the archive:

     you% cd /some/place
     you% find . -depth -print | /prog/to/remove-crap |
          pax -wd -x cpio | gzip -c > /tmp/x.pax.gz

   When reading it:

     you% cd /other/place
     you% gunzip -c < /tmp/x.pax.gz | pax -r -pe

   Why do the compression outside of pax?  Because now you have a choice
   of gzip -1c (fast compression), bzip2 (better compression), xz (*way*
   better compression), etc.  If you have a ton of files to move, you can
   break up the list:

     you% cd /some/place
     you% mkdir /tmp/work /tmp/copy
     you% find . -depth -print | /prog/to/remove-crap | split - /tmp/work/x

     you% for file in /tmp/work/x*; do
        > b=`basename $file`
        > pax -wd -x cpio < $file | gzip -c > /tmp/copy/$b.pax.gz
        > scp /tmp/copy/$b.pax.gz wherever    # and remove it
        > rm $file
        > done

Karl Vogel                      I don't speak for the USAF or my company

Why no one ever uses the Restroom on "Star Trek" #7:
Special effects dept. draws a blank on Hi-tech toilets.

More information about the freebsd-questions mailing list