Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    

3 Answers 3

up vote 8 down vote accepted

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
share|improve this answer
    
That worked perfectly, thanks! Unix rocks :) –  Rich Jan 30 '12 at 13:59

Why don't you use archival rsync?

rsync -avzHAX foldertocopy user@remoteserver:/file/path/to/copy

This way you can save every detail about the file, also with "z" rsync compresses the stream on the fly.

share|improve this answer
    
Will that work if user@remoteserver can't create the files with the right privs? –  Rich Jan 30 '12 at 15:30
    
No, but you should be able to run it in sudo. –  Simon Richter Jan 30 '12 at 17:56
    
rsync will copy files but will fail to set the owners. I'm always working with root so I never experienced it. So yes, this solution may not help you. But there's always root :) –  SilentStorm Jan 30 '12 at 19:29

One solution to the problem is to have ssh run the untar directly:

tar cfzp - foldertocopy | ssh me@machine "cd rightplace; tar xzf -"
share|improve this answer
    
Will that work even though my user on the remote machine doesn't have the rights to create the files with the correct owner/privs? I can sudo su - on the remote machine, but I don't know if it's possible to do this from within the command executed by ssh...I have to specify a password when doing sudo su -. –  Rich Jan 30 '12 at 13:41
    
This is the right solution, but you should do it backwards. SSH to the machine, write a shell script that logs back to your machine and uses tar cf ... | tar xf to transfer the data, and then sudo ./shellscript. You can make the shell script owned by root and only readable by root because your login password will be in it. And delete it after the transfer. –  Michael Dillon Feb 1 '12 at 7:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.