netcat tar backup

debian netcat-openbsd is leaner, cleaner & more efficient than debian netcat-traditional. if you get a choice, prefer the openbsd version.

i now use busybox wherever i can, including nc and tar. small, simple, clean, standard, available the same everywhere.

$ busybox nc

Usage: nc [-iN] [-wN] [-l] [-p PORT] [-f FILE|IPADDR PORT] [-e PROG]

Open a pipe to IP:PORT or FILE

-e PROG Run PROG after connect
-l      Listen mode, for inbound connects (use -l twice with -e for persistent server)
-p PORT Local port
-w SEC  Timeout for connect
-i SEC  Delay interval for lines sent
-f FILE Use file (ala /dev/ttyS0) instead of network

$ busybox tar

Usage: tar -[cxtZzJjahmvO] [-f TARFILE] [-C DIR] [FILE]...

Create, extract, or list files from a tar file

        c       Create
        x       Extract
        t       List
        f       Name of TARFILE ('-' for stdin/out)
        C       Change to DIR before operation
        v       Verbose
        Z       (De)compress using compress
        z       (De)compress using gzip
        J       (De)compress using xz
        j       (De)compress using bzip2
        a       (De)compress using lzma
        O       Extract to stdout
        h       Follow symlinks
        m       Don't restore mtime

at {destination}:
$ nc -l -p {port} | tar xpv[z|j]f -

at {source}:
$ tar cpv[z|j]f - {directory} | nc {destination host/ip} {port}

[z|j] compression: use over slower networks. ignore for faster networks and/or slower computers.

tar streams much faster copying than scp 'ping-pong', especially when you have lots of files.

copy files from {some-server} to your machine:
$ ssh {some-server} ‘cd /some/dir && tar cz dir’ | tar xz

and the other direction:
$ tar cz dir | ssh {some-server} `cd /some/dir && tar xz`

image a disk across the network from {box1} to {box2}:

at {box2}:
$ nc -l {port} [-vv] | dd of={disk.img} bs=1M

at {box1}:
$ dd if=/dev/sda bs=1M | nc {box2 host/ip} {port} [-vv] -q 10

[-vv] use at the box1 (and/or box2, if fast enough)

restore this image in {box2} to {box3}:

at {box3}:
$ nc -l {port} [-vv] | dd of=/dev/sda bs=1M

at {box2}:
$ dd if={disk.img} bs=1M | nc {box1 host/ip} {port} [-vv]

compressed backup

at {box1}:
$ tar cpvJf - {directory} | nc {box2 host/ip} {port}

at {box2}:
$ nc -l -p {port} | dd of={directory}.tar.xz bs=1k


No comments:

Post a Comment

most popular posts