Operating System - HP-UX
1834679 Members
3021 Online
110069 Solutions
New Discussion

How to use tar in following senario

 
SOLVED
Go to solution
David Fosgate_2
Occasional Advisor

How to use tar in following senario

As a newbie to script and Unix in general. I need to copy directory A ( and all subdirectories) from system A and ftp it to system B and restore directory A and all its subdirectories on this system. I tried using tar to get all the directory information into on tar, but didn't get the subdirectories.
I need the steps to tar up the source box directory and restore the directory to the target box, including all subdirectories.

Thanks

Dave
9 REPLIES 9
Victor BERRIDGE
Honored Contributor
Solution

Re: How to use tar in following senario

The best would be to:
1) check that you can use a remote shell without having to enter a passwd, that is create a .rhosts where needed...
2)
from the source node:
tar -cf - ? remsh dest_node "(cd dir2;tar -xvf -)"

Good luck
Victor
Victor BERRIDGE
Honored Contributor

Re: How to use tar in following senario

Going in the directory works also:
on node1, cd dirA
tar -cf - *? remsh node2 "(cd /dullpath/dir2;tar -xvf -)"

All the best
Victor
Rainer_1
Honored Contributor

Re: How to use tar in following senario

i wonder that tar does not contain any subdir.
Posibly you have tar'ed a sym link ? then you should use the h option within tar.
Here the steps for your job:

At hostA:
cd
tar cvhf - . |gzip -c >/var/tmp/dir.tar.gz
ftp hostB
binary
cd /var/tmp
put /var/tmp/dir.tar.gz

At hostB:
cd
gzip -dc
(I have used the combination with gzip to reduce the ftp traffic)
Keith Hughes_2
Advisor

Re: How to use tar in following senario

Logged in as root to create a tar backup of /home

tar -cvf /home.tar /home

to list the contents of a tar backup

tar -tvf /home.tar

ftp to new box

perform tar restore

tar -xvf /home.tar

Good Luck
Trevor Dyson
Trusted Contributor

Re: How to use tar in following senario

tar should pick up sub directories unless you do not have permision to read them. If so you would see error messages.

What is the command line you are using for tar?

If you are able to use remsh then you would also be able to use rcp with the -rp options to preserve timestamps and copy recursively, eg:

rcp /data hostb:/newdata

recursively copies the directory /dat on the local system to the the director /newdata on a system with a hostname of "hostb"
I've got a little black book with me poems in
Dan Hetzel
Honored Contributor

Re: How to use tar in following senario

Hi David,

Victor is right, that's the way to go.
I'd like to add one more (quite obvious) point: make sure you have read permission on all files and subdirectories on host A, and that you have write permission in the destination directory on host B.

The easiest would be to be logged in as root, this means that the file /.rhosts (on host B) should have one line with the name of host A.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
David Fosgate_2
Occasional Advisor

Re: How to use tar in following senario

I would like to use Victor's method.
On the target server I have added the source server name to /.rhosts and /etc/hosts.allow files.
On the source server I have added the target server name to /.rhosts and /etc/hosts.allow files.

When I run the following command:
tar -cf - * | remsh hammer "(cd /home/dave;tar -xvf -)"

I get:
rcmd: hammer: Unknown host, should I be using IP address?
Rainer_1
Honored Contributor

Re: How to use tar in following senario

first check your /etc/hosts or if you have DNS try nslookup hammer
Of course you could use the IP address
David Fosgate_2
Occasional Advisor

Re: How to use tar in following senario

Rainer

That /etc/hosts was the issue, I'm using Victor's solution although the others worked as well.

Thanks to you all !!!

Dave