Backup using TAR over SSH

Frequently I backup my files (source code, toolchains, etc) between my main development computer, and my backup development computer. Unfortunately, my main development computer doesn't have that much disk space, so it's impossible to make a tarball of my backup before moving it to another computer. This is where "tar over ssh" comes into play (note: For more examples, see ssh secrets).

For my demonstration, I'll use my two linux development machines at work:

  1. linuxdev2 - Main compiling machine
  2. linuxdev1 - Backup compiling machine

Here's some stats on the disk usage of the machines:
Linuxdev2:
[peterb@linuxdev2 peterb]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2             5.6G  5.1G  206M  97% /
/dev/hda1              99M  9.2M   85M  10% /boot
none                   62M     0   62M   0% /dev/shm
[peterb@linuxdev2 peterb]$

Linuxdev1:
peterb@linuxdev1 peterb $ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda3             5.5G  3.9G  1.7G  71% /
none                  117M     0  117M   0% /dev/shm
peterb@linuxdev1 peterb $

Let's say that I want to backup my cross-compiler toolchain (who's size is greater than my 206MB of free space on linuxdev2) to linuxdev1. What I need to do, is tar my toolchain directory to standard output, and pipe that to a SSH tunnel. This SSH tunnel will then output to a remote tar command, which will in turn place the files onto the remote machine. Both machines share an Ethernet segment, so I'm not too worried about compressing the data.

Let's see the command..

[linuxdev2 peterb]$ tar cvf - cross | ssh peterb@linuxdev1 "tar xpvf -"

A Few minutes later, the entire directory structure now resides on linuxdev1.


Back to index