![]() |
![]() |
Backing up files with tar and netcatJune 19, 2004 at 14:59, by Geoff Richards What is netcat?Netcat (usually the command is actually called Netcat simply establishes a TCP/IP network connection to a particular port (of your choosing) and sends data to and from it. It can also listen for connections on a port and talk to whatever connects. You can use it to test server programs (like webservers) by talking to them directly, or test client programs by having them talk to netcat rather than a real server, so that you can see what they're saying. Transfering files over a network with netcatIf your stuck in a corner trying to transfer large amounts of data over a network (maybe you don't want to set up an FTP server, or very large files are causing problems with the file transfer programs you'd usually use) then netcat save the day. Here's how to do it. On the machine that should receive the data, run netcat in ‘listen’ mode, writing data it receives on some arbitrary high-numbered port into a file: nc -lp 1234 >backup.tar.gz Whatever data gets sent to port 1234 will get fed into the file backup.tar.gz. Then tar up the files you want to back up on the sending machine, and send them over the network to the same port: tar czvf - stuff... | nc -q 0 backup-hostname 1234 The For some reason tar sends a load of extra null characters at the end when it's writing to a pipe, but that doesn't seem to cause any problems when extracting it. It'll be something weird to do with magnetic tapes. You can also use dd if=/dev/cdrom bs=2k | nc -q 0 backup-hostname 1234 |
© Copyright Geoff Richards, 2004 |