Fast copy with tar and ncat
Hot take alert
You don’t need
rsyncorscpto copy a large amount of data between two machines…
…provided that:
- You don’t need encryption.
- Target machine is directly accessible from source machine.
Do that instead:
- Install
tarandncaton both machines (if they aren’t installed already). - Pick a port number. I’m gonna use
34567here. - Open that port in the firewall on the target machine.
For RedHat-based distributions the command likely is:
sudo firewall-cmd --add-port 34567/tcp
For Debian-based distributions the command likely is
sudo ufw allow 34567/udp
cdto the target directory on the target machine.- Run the following command on the target machine:
ncat -l 34567 | sudo tar xf -
cdto the source directory on the source machine.- Run the following command on the source machine:
sudo tar cf - . | ncat TARGET_HOST_OR_IP 34567
You can also:
- Add
pvin betweentarandncaton one or both ends to see data transfer rate. - Read
tarmanual and add flags to preserve SELinux or other attributes. - Use that approach with
cat,ddor something else instead oftarif you transfer something that is not a directory.