1827963 Members
2469 Online
109973 Solutions
New Discussion

Tar question

 
Angie_1
Regular Advisor

Tar question

I need help with tar please. How do I tar up a bunch of files but at the same time untar it to another filesystem? That way I don't have to tar a directory. And then untar when its all done to that location?

Thanks - Angie
8 REPLIES 8
A. Clay Stephenson
Acclaimed Contributor

Re: Tar question

Generally that a task a bit better suited to cpio using the pass (-p) option; some thing like this:

cd to desired source dir:
find . -print | cpio -pudvm /xxx/yyy/zzz where /xxx/yyy/zzz is the destination directory/filesystem.
If it ain't broke, I can fix that.
RAC_1
Honored Contributor

Re: Tar question

tar -cvf - /source_dir/file1 /source_dir/file2 | (cd /dest;tar -xvf -)

Anil
There is no substitute to HARDWORK
Patrick Wallek
Honored Contributor

Re: Tar question

This assumes you have remsh access from your SOURCE system to the DESTINATION system.

On the SOURCE system:

# cd /dir
# tar -cf - . | remsh DESTINATION "cd /dest_dir ; tar -xf -"

This could also be done if you have SSH access between the 2 systems.

# cd /dir
# tar -cf - . | ssh DESTINATION "cd /dest_dir ; tar -xf -"
Angie_1
Regular Advisor

Re: Tar question

I should have been more clear.
Both NFS filesystems are mounted on this server.

So I need to tar up a directory on one filesystem and untar it to the other location.

So is this below correct? Why the "-" after "-cvf" and "-xvf"?

Angie

tar -cvf - /source_dir/file1 /source_dir/file2 | (cd /dest;tar -xvf -)
Doug O'Leary
Honored Contributor

Re: Tar question

Hey;

Not quite but very close. You want to cd into the source directory; otherwise, you'll end up with /dest/source_dir/file# instead of /dest/file#.

So, the full, correct syntax:

cd /source
tar -cf - . | (cd /dest; tar -xf -)

Without the -v, you won't see the file names as they get processed. If you want to see them, put the -v in one and only one of the tar commands, otherwise you'll see the filenames twice...

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Angie_1
Regular Advisor

Re: Tar question

Doug,

Thank you for clarifying.
Now one last question... to find out how much was tarred/untarred... is there a simple way to do this (in megs)? Or how do you get the results at the end?

Angie
Doug O'Leary
Honored Contributor

Re: Tar question

Hey again;

If you were creating a regular tar ball, you could simply examine the size of the resulting file. In this case, since you're immediately extracting the tar, the best easiest way would be to simply:

du -sk /dest

That will give the size of the resulting dest dir in K; divide by 1024 to get megs.

BTW, to answer your other question that I missed -f - means to create the tar file to standard out or extract it from standard in.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
H.Merijn Brand (procura
Honored Contributor

Re: Tar question

You say you're using NFS. Though NFS is VERY handy (I use it all the time), it is also very slow, especially when writing.

All the answers given (except the remsh and ssh one's), cd to the source dir, and then write to the dest dir, probably assuming the server you work on is the one that has the dest dir mounted NFS

It will be extremely much faster -- if the NFS is two way -- to do this on the receiving server, where the source dir is on the mounted NFS. Read ops don't lock as much as write ops, and locking is the most expensive NFS operation.

my options:
1. ssh
2. remsh
3. rcp (make a tar on machine 1, untar on machine 2)
4. NFS

Then as last tip, you can speed up the extraction by adding a dd to better stream the data, where dd just acts as a buffer

# cd dest
# ( cd source ; tar cf - . ) | dd | tar xvf -

Do not use -v on both ends. Then you will get all the files listed twice

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn