How do I copy a file from one server to another without downloading first?

by Corey   Last Updated June 28, 2018 23:01 PM

Is it possible to copy a file from one server to another without downloading first?

I have a backup file that is 10gb that I'm wanting to copy from my production server to my staging server.

Currently I'm just doing it through Transmit, but that downloads the file first, and then uploads it.

Is there a way to directly move the file from the production server to the staging server? Does SCP do this or does it download it first? How about rsync?

EDIT

Both are linux servers running Ubuntu 14.04 LTS.



Answers 2


I'm presuming these are both linux servers as you've mentioned scp (yes I am aware scp exists for windows).

Simply ssh onto one of the servers, then scp the file directly to the other server.

scp file user@server:/location/

Infact, if your version of scp supports it (I've not used one that doesn't but the online man pages don't seem to document this feature) you can use -3 which will move a file between two hosts, via the local host.

scp -3 file user@server:/location/

This will use the local systems bandwidth, but it won't 'save' a copy of the file locally.

You could also use rsync to achieve the same, however the command is slightly different and I'm not versed well enough to know it off the top of my head.

djsmiley2k
djsmiley2k
July 19, 2016 17:33 PM

Hmm... ...From the sound of it, perhaps one of the systems is limited in some fashion, or maybe time is a factor. Short version: SCP is great for a one shot copy, with some caveats. I'll assume there are 3 servers involved here: Server A is the destination, server B is the remote location with the file, and server C is the machine you want to run the copy operation (C for copy). I would checksum the file on server B, then scp will copy the file, and if you use -3 it will be a fast, no check copy. Then I'd loop a checksum of the file on server A after the copy and compare that to the checksum from server B. If they match, you're done, close the loop; if not run the copy again and the checksum. If you just use the SCP with default options, the file will be cached on Server C, then copied to server A. This prevents problems in transit, and allows for other network traffic. If you want to mimic this, but perhaps a little faster, you can alter the first example with the -3 flag, and instead copy the file to server C, then copy the file to server A, checking the file at server A with a checksum comparison to the file on server B (you can repeat the copy if necessary). This is a similar operation, but allows you to delete the file from server C at the end, so that there's no cacheing overhead waiting to be freed up. I don't like playing with freeing up cached resources, especially in an active production environment. One mistake makes a big mess. I like a simpler option where the file is accessible directly so I can delete it from my own script. I'm also less practiced in some of the more advanced controls. I hope this helps.

Htd Tech
Htd Tech
June 28, 2018 22:34 PM

Related Questions



Remote sync without rsync

Updated February 27, 2018 21:01 PM

Job to copy file from one server to another server

Updated September 21, 2017 15:01 PM