| Webtraffic Exchange | Linux

Remote backup with Tar and SSH

If you wish to make a backup of a file system between two Unix machines, you may use scp command.

scp {filename} {username@hostname}:{remote filename}

The scp command will copy file (or directory) one at a time uncompressed, so it will take a longer time to transfer files between two machines. On the other hand, if you use tar command, it will compress the file (or directory) before transferring so it will take less time to transfer. The time it will take to compress will be much less than the time it will take to transmit larger content.

tar cfz - {directory} | ssh {username@hostname} "cat > {remote file}"
example> tar cfz - /home |ssh root@hostname "cat > /home/home.tgz"
username@host's password:

You may also use dd in place of cat command.

tar cfz - {directory} | ssh {username@hostname} "dd of={remote file}"
example> tar cfz - /home |ssh root@hostname "dd of=/home/home.tgz"
username@host's password:

Finally, if you wish to explore the archive at the remote end, you may wish to combine the command.

tar cfz - {directory} | ssh {username@hostname} "(cd {directory}; tar xfz -)"
example> tar cfz - /home |ssh root@hostname "(cd /home; tar xfz -)"
username@host's password:
Share this Post: Facebook X LinkedIn Email


0 Comments

Comments are moderated to keep the discussion useful and respectful. Spam, automated submissions, and low-value promotional comments are removed.

  • No comments have been published yet.

Leave a Comment

Related Articles