Friday, March 30, 2012

How to transfer file on remove host using tar, rsync over SSH?

How to transfer file on remove host using tar, rsync over SSH?


a. Copying files from remote machine to your local machine

$ ssh user@remote_server "tar -czpf - /files/to_copy" | tar -xzpf - -C /files_to_extract
$ ssh filetran@goyouk "tar -czpf - /opt/datafile" | tar xzpf - -C /opt/importfile

b. Copying files from your machine to your remove machine.

$ tar -cXpf - /Files/To_transfer | ssh user@what_machine_to_transfer "tar -xpf - -C /where?to_transfer
$ tar -cXpf - /opt/datafile | ssh filetran@baypak "tar -xpf - -C /opt/exportfile

Without compression,
$tar -cf - /opt/datafile | ssh remote_host tar -xf - -C /destination

with compression,
$ tar -czf - /opt/datafile | ssh remote_host tar -xzf - -C /destination

if you have ssh key set up, you can use,
$ tar -czf - /opt/datafile | ssh remote_hostname tar -xzf - -C /some/destination

To copy locally within the server,

$ tar cf - /opt/datafile | (cd /export/data/tab; tar xf -)

--------------------------------------

Using rsync

rsync -e ssh [-avz] /some/file [ more ... ] host.name:/destination/file
rsync -e ssh /opt/dd_data remove_host:/opt/dd_data

-or-

rsync -ave ssh source_server:/path/to/source /destination/dir