Copy arbitrary bits of the filesystem between servers using ssh and tar
Shuffling files between servers is simple with scp :
root@inky:~# scp some-archive.tgz blinky:/
Or even copying many files at once:
root@pinky:~/tmp# scp clyde:/usr/local/etc/* .
But scp isn't designed to traverse subdirectories and preserve ownership and permissions. Fortunately, tar is one of the very early (and IMHO, most brilliant) design decisions in ssh to make it behave exactly as any other standard Unix command. When it is used to execute commands without an interactive login session, ssh simply accepts data on STDIN and prints the results to STDOUT. Think of any pipeline involving ssh as an easy portal to the machine you're connecting to. For example, suppose you want to backup all of the home directories on one server to an archive on another:
root@inky~# tar zcvf - /home | ssh pinky "cat > inky-homes.tgz"
Or even write a compressed archive directly to a tape drive on the remote machine:
root@blinky~# tar zcvf - /var/named/data | ssh clyde "cat > /dev/tape"
Suppose you wanted to just make a copy of a directory structure from one machine directly into the filesystem of another. In this example, we have a working Apache on the local machine but a broken copy on the remote side. Let's get the two in sync:
root@clyde:~# cd /usr/local root@clyde:/usr/local# tar zcf - apache/ \ | ssh pacman "cd /usr/local; mv apache apache.bak; tar zpxvf -"
This moves /usr/local/apache/ ...