Shell Commands to SCP with Tar compression

Do you have couple of Giga, Tera byes of data to transfer between servers?. Did you have to move your files in to a new server?. Did you try rsync, scp and those take a long time or timeout the session?.

Well, the solution is simple, you can compress the and send the output to the SCP stream.

# From Server #1 to Server #2 and you logged in to Server #1

tar czf - /var/www/ | ssh [email protected] tar xzf - -C ~/

# From Server #1 to Server #2 you have logged in to the Server #2

ssh [email protected] "tar czf - /var/www" | tar xzvf - -C /var/www