Linux / Unix Tips and Tricks

This blog contains Linux / Unix Tips and Tricks, collected during my work as a Unix System Administrator.
They are here for my own reference, but they might help you as well !

How do I copy data from one system to another

len | 11 December, 2008 21:34

Suppose you want to copy a directory structure from one machine to the other.
You could create an archive (using tar or cpio), copy over the archive and extract it.
But there's a better way to do it by combining tar and ssh.

Suppose you want to copy all data in /opt/data on machine1 to the directory /backup/data of machine2:

On machine1:

# cd /opt/data
# tar cvf - * | ssh machine2 "( cd /backup/data ; tar xf - )"

This will copy all data in /opt/data to machine2:/backup/data without the need of a temporary archive file.
This method will preserve all file and directory permissions, time stamps, symbolic links, etc.

 
Accessible and Valid XHTML 1.0 Strict and CSS
Powered by LifeType - Design by BalearWeb