Tagged: Network

Backup a system to a remote location using ‘netcat’ and ‘tar’

I use to say “backup is only for wimps”. But to be honest, I do backups. And I even store the backup media in a save place.

To get the data onto a backup device and put that one to a save place, sometimes you have to write the backup over the network.

netcat or nc, the swiss army knife of networking is a big help for that.

On the remote system, where you want to write the backup start netcat:

nc -l -p 12345 > /var/backup/name-of -the-backup-2010-08-18.tgz
  • -l means listen
  • -p <number> is the port, where nc listens.

On the system you want to backup  you can exclude some directories, like /proc and /sys from being backed up. So run:

echo "./proc
./tmp" > /tmp/X

Now it is time to start the backup:

cd /
tar -X /tmp/X -czpf - . | nc 12345

So you cd into the root directory, exclude the files listed in /tmp/X, write the backup to STDOUT  and backup everything under the current directory. The backup is done relative.

Of course, you could use a backup command like tar -czpf – /,  but then the backup is done absolute. You realize the advantage of doing relative backups, when you want to restore the backup into a directory. With an absolute backup everything is written back to the original location.

Network grep “ngrep”

Sometimes it is very practical to use grep, to find a specific regular expression in some files. It would also be very practical to have the grep functionality on the network. This feature is available.

Download ngrep. The package to get is ngrep-1.45.tar.bz2.

To get it to work on a mac do:

tar xvjf ngrep-1.45.tar.bz2
cd ngrep-1.45
./configure --with-pcap-includes=/usr/include --prefix=/usr/local
sudo make install

To read the manual page you can run

man ngrep

Now run ngrep itself run

sudo ngrep  <expression to find> <pcap filter expression>

<pcap filter expression> is used the same way as in tcdpdump.