DISCLAIMER: Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog.
You may use the commands/method/scripts on your own responsibility.
If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.
Note: The blog is best viewed with 1680x1050 pixel settings.
The default behaviour of (un-)tar is to extract everything at its original location. Sometimes, it is required to extract/restore to some other location (eg. for comparision or analysis before putting data back to original location). I found that default tar binary provided with Solaris does not provide any option to restore/untar in different location. Hence I needed to use GNU Tar (gtar) for this purpose. In following demo, I will show how to restore in different directory:
Part 1: Creating a tar archive of a directory /tmp/A
# ls -la /tmp/A total 6 drwxr-xr-x 2 root root 512 Jan 27 12:08 . drwxrwxrwt 15 root sys 1536 Jan 27 12:12 .. -rw-r--r-- 1 root root 0 Jan 27 12:08 a -rw-r--r-- 1 root root 0 Jan 27 12:08 b -rw-r--r-- 1 root root 0 Jan 27 12:08 c
# tar cvf /dev/rmt/14 /tmp/A a /tmp/A/ 0 tape blocks a /tmp/A/a 0 tape blocks a /tmp/A/b 0 tape blocks a /tmp/A/c 0 tape blocks
# tar tvf /dev/rmt/14 drwxr-xr-x 0/0 0 Jan 27 12:08 2009 /tmp/A/ -rw-r--r-- 0/0 0 Jan 27 12:08 2009 /tmp/A/a -rw-r--r-- 0/0 0 Jan 27 12:08 2009 /tmp/A/b -rw-r--r-- 0/0 0 Jan 27 12:08 2009 /tmp/A/c =========================================================================== Part 2: Extracting tar archive - to original location (i.e. /tmp/A)
# tar xvf /dev/rmt/14 x /tmp/A, 0 bytes, 0 tape blocks x /tmp/A/a, 0 bytes, 0 tape blocks x /tmp/A/b, 0 bytes, 0 tape blocks x /tmp/A/c, 0 bytes, 0 tape blocks
=========================================================================== Part 3: Extracting tar archive - to Different location (i.e. /tmp/B) # gtar -C /tmp/B -xvf /dev/rmt/14 /tmp/A/ gtar: Removing leading `/' from member names /tmp/A/a /tmp/A/b /tmp/A/c
# ls -latrR /tmp/B /tmp/B: total 8 drwxrwxrwt 14 root sys 1536 Jan 28 10:25 .. drwxr-xr-x 3 root root 512 Jan 28 10:26 . drwxr-xr-x 3 root root 512 Jan 28 10:26 tmp
/tmp/B/tmp: total 6 drwxr-xr-x 2 root root 512 Jan 27 12:08 A drwxr-xr-x 3 root root 512 Jan 28 10:26 .. drwxr-xr-x 3 root root 512 Jan 28 10:26 .
/tmp/B/tmp/A: total 4 -rw-r--r-- 1 root root 0 Jan 27 12:08 a -rw-r--r-- 1 root root 0 Jan 27 12:08 b -rw-r--r-- 1 root root 0 Jan 27 12:08 c drwxr-xr-x 2 root root 512 Jan 27 12:08 . drwxr-xr-x 3 root root 512 Jan 28 10:26 ..
Note: gtar is located at /usr/sfw/bin/gtar in Solaris 9 and Solaris 10.
I used "cp -pr " method for many years to recusive copy of data from one source to another destination. But, recently I came across some drawbacks of this method and hence shifting to another method. :-)
The main disadvantage of copying bulk data was related to soft links. If the source data has any softlink that points to itself, then this command (cp -pr) can NOT be used. It will fill up the file system fast without complaining.
To overcome linked related problem, here is the new method I am using now:
date; cd /source_directory; tar cvf - * | ( cd /target_directory; tar xvfp -) ; date
If I dont need verbose output, I can use following:
date; cd /source_directory; tar cf - * | ( cd /target_directory; tar xfp -) ; date