Operating System - HP-UX
1845868 Members
4619 Online
110250 Solutions
New Discussion

how to tar some directories

 
SOLVED
Go to solution
praveen..
Super Advisor

how to tar some directories

i need to take the backup of some subdirectories and place it into another directory using tar,
how can i do it?

#cd /praveen/data
#ll
total 0
drwxr-xr-x 2 root root 96 Jan 21 13:17 lost+found
drwxrwx--x 4 praveen dba 96 Jan 3 01:10 share.orig

I need to take the backup using tar of share.orig directoy and place into /praveen/backup

can anybody suggest me the tar command with full options?

thanks
6 REPLIES 6
Patrick Wallek
Honored Contributor
Solution

Re: how to tar some directories

The man pages are your friend. 'man tar' for usage on tar.

# cd /praveen/data
# tar -cvf /praveen/backup/share.orig.tar ./share.orig

The above will create a tar file called share.orig.tar in /praveen/backup. That tar file will contail the share.orig directory in /praveen/data.
praveen..
Super Advisor

Re: how to tar some directories

I had done this thing.

but can you please tell me how to test and extract it in other directory "/praveen/newbackup"
Patrick Wallek
Honored Contributor

Re: how to tar some directories

# cd /praveen/newbackup
# tar -xvf ./share.orig.tar

Will extract a tar archive. Now this assumes that the archive was created with relative paths, the ./share.orig that I gave in my example. If it was created with explicit paths , /praveen/data/share.orig, then you are out of luck as the archive will be extracted back to the same place.
James R. Ferguson
Acclaimed Contributor

Re: how to tar some directories

Hi Praveen:

Since the archive was created with relative paths and not absolute ones, you can simply 'cd' into a directory to which you want to restore and do:

# tar -xvf archivename

Had the archive been created with absolute paths for its files, you could have used 'pax' to substitute (or strip) the parts of the path you didn't want.

Regards!

...JRF...
dipesh_2
Regular Advisor

Re: how to tar some directories

Hi Praveen,

#tar -cvf /praveen/backup/share.orig.tar ./share.orig

with this command you can create a backup of share.orig to /praveen/backup/share.orig.tar file

# tar -xvf ./share.orig.tar

with this command you can extract share.orig.tar file
Shivam Tiwari
Honored Contributor

Re: how to tar some directories

Hi Praveen,

Its dependent on when you create a tar file for example if you are creating a tar for PRAVEEN dir which resides in
/root/home/PRAVEEN

sp if you issue this command to create tar
#tar -cvf PRAVEEN.tar /root/home/PRAVEEN
now if you untar it. It will always be untar in /root/home/PRAVEEN

but if you do like this
#cd /root/home
#tar -cvf PRAVEEN.tar PRAVEEN

Now if you untar this file it will untar in the current directory on the system whereever you are.

HTH,

Shivam Tiwari
Never say No. Say I will Do it........