Fast copy with tar and ncat
Hot take alert
You don’t need
rsync
orscp
to 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
tar
andncat
on both machines (if they aren’t installed already). - Pick a port number. I’m gonna use
34567
here. - 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
cd
to the target directory on the target machine.- Run the following command on the target machine:
ncat -l 34567 | sudo tar xf -
cd
to 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
pv
in betweentar
andncat
on one or both ends to see data transfer rate. - Read
tar
manual and add flags to preserve SELinux or other attributes. - Use that approach with
cat
,dd
or something else instead oftar
if you transfer something that is not a directory.