How to utilize tar and untar over SSH in red hat linux
Hi, I have installed red hat linux in my machine but as I am newer to this operating sysmte I don’t know about the feature and functioning about the operating system and have some doubt regarding that.
Actually the thing is like I have two linux server and I want to exercise tar over ssh to tar and untar the file. The server A uses IP 10.1.1.a there is directory “A” which contain files. The server B uses IP 10.1.1.b , and here also dir ”b” contain file .
So, in above case, how can I tar over ssh in such way that the file in directory “a”, server a can tar to server b ,directory “b” .
Please help me with the situation.
Re: How to utilize tar and untar over SSH in red hat linux
First of all let me tell you as I am not getting whatever you have mentioned in the problem sectioned but still as far as commands are concern I would like to tell you about them so that you can make use of them.
- ar
- basename
- cd
- chown
- cpio
- csh
- dirname
- ls
- mt
- pack
- pax
- setfacl
- umask
- zcat
Re: How to utilize tar and untar over SSH in red hat linux
See I am hoping that you are asking about opening the tar files and untar it again, thus for that I would like to tell you about the command lines that actually uses.
For tar:
tar -pczf filename.tar.gz www/
for untar
tar xvfz filename.tar.gz
Re: How to utilize tar and untar over SSH in red hat linux
I am not sure about this but still as idea of tarring over ssh you can use the below mentioned command line:
Code:
ssh user@srcbox 'tar cf - srcpath' | tar xf - trgt
or simply you can have see another example as well.
To copy SOURCEDIR into DESTDIR
localhost% tar zcvf - SOURCEDIR | (cd DESTDIR; tar zxvf -)
Re: How to utilize tar and untar over SSH in red hat linux
I am hoping that you must be thinking of actually copy whole trees from one location to another and for that There are basically 2 methods, PUSH & PULL. You can refer the below mentioned examples.
-------------Pushing a directory from local host to remote host
1. tar & ssh
1 - copy SOURCEDIR from localhost to remotehost over ssh. Untarring begins in /home/user1
localhost% tar zcvf - SOURCEDIR | ssh user1@remotehost tar zxvf -
2 - copy SOURCEDIR from localhost to remotehost over ssh. Untarring in DESTDIR
1
localhost% tar zcvf - SOURCEDIR | ssh user1@remotehost 'cd DESTDIR; tar zxvf - '
2
localhost% tar zcvf - SOURCEDIR | ssh user1@remotehost "(cd DESTDIR; tar zxvf -)"
3
localhost% tar zcvf - SOURCEDIR | ssh -l user1 remotehost 'cd DESTDIR ; tar zxvf -'
4
localhost% tar zcvf - SOURCEDIR | ssh user1@remotehost "cat > /DESTDIR/DESTFILE.tar.gz"
------------- Pulling a directory to localhost <— remotehost
copy SOURCEDIR to DESTDIR
1
localhost% ssh remotehost 'tar zcvf - SOURCEDIR' | tar zxvf -
2
localhost% ssh -n remotehost 'tar zcvf - SOURCEDIR' | tar zxvf -
3
localhost% ssh remotehost "( cd SOURCEDIR ; tar zcvf - SOURCEFILES ) " | tar zxvf -
Re: How to utilize tar and untar over SSH in red hat linux
Hey thanks for the suggestion, I have tried this and some of them works perfectly but some of them didn’t, why so?