stdin and stdout with tar
While archiving, we can specify stdout as the output file so another command in a pipe can read it as stdin and process the archive.
This technique will transfer data through a Secure Shell (SSH) connection, for example:
In the preceding example, the files/directory is added to a tar archive which is output to stdout (denoted by -) and extracted to the Documents folder on the remote system.
Receiving server(open port 44023)
root@Receiver:/StoragePool/data/logs/Firewalls/2020/11# nc -l 44023 | pv | tar x
2.27GiB 0:01:16 [46.6MiB/s] [ <=> ]
Sending server (send dir named 12 to 22)
root@Sender:/opt/immune/storage/logs/Firewalls/2020/11# ls
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
root@Sender:/opt/immune/storage/logs/Firewalls/2020/11# tar cf - 13 14 15 16 17 18 19 20 21 | nc 172.16.104.39 44023
The sender server should run the following command
$ tar cf - logs/ | netcat 192.168.0.1 9000
and the receiveing server should listen with with this command
$ netcat -l -p 9000 | tar x
No comments:
Post a Comment