2009-05-11

Remote "tar" backups via SSH

My first "real" entry to this blog is an easy method I have found this morning to perform a remote "tar" backup using SSH. It should be general enough to be applicable under any Unix system (I have tested it on Mac OS X 10.5 and Debian Lenny).
The problem I had was the following:
  1. I had a lot of data (~ 33 Gb) on computer "foo" which wanted to back up before formatting the hard disk and installing FreeBSD 7.2;
  2. There was however not enough room in computer "foo" to create the .tar file (just 13 Gb);
  3. Thanks to a colleague, I had access to another computer "bar" with lot of free space (~750 Gb).
I solved this problem with the following command:
tar cvz -f - ./ | ssh bar "cat > \
  backup.tar.gz"
The "tar" process will write the .tar.gz file containing data from the "./" directory into the pipe. The "ssh" sends whatever is written into the pipe to the "bar" computer, where a "cat" command will save the data into "backup.tar.gz". This results in the .tar.gz file being written directly on the remote computer.