Copying large tree from one machine to another, maintaining ownership

file-copyrsyncscp

I am trying to copy a large folder structure between machines. I want to maintain the ownership/rights during the copy as it is not reasonable to 'fix' the privs afterwards.

Therefore, I am using the following command to tar the file with privs intact and transfer the data to the destination machine. The same users exist on both machines.

tar cfzp - foldertocopy | ssh me@machine "cat > /applications/incoming/foldertocopy.tar.gz"

The transfer works fine, and the next step is to su to root on the remote machine and untar the file.

The problem is: there isn't enough disk space to store both the compressed and uncompressed data at the same time.

I could use rsync/recursive scp but my user doesn't have the rights to create the files with the correct privs itself and root can't log in remotely.

What are my options? The source machine is RHEL4 and the destination is RHEL5.

Best Answer

As root, set up a named pipe:

# mkfifo /tmp/fifo
# chmod o+w /tmp/fifo

Then, transfer your data as me:

$ tar cfzp - foldertocopy | ssh me@machine "cat > /tmp/fifo"

But read it as root:

# tar -xfzp /tmp/fifo
Related Question