Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm backing up and transferring files automatically each night via scp.

I realize I get packet-level checksums via the protocol itself, but I'm wondering what the best practice is to ensure that a transfer hasn't failed, or partially completed etc.

I could use rsync, but my needs are simple and I just want to ensure that:

  1. there wasn't an error in transmission
  2. retry if there was (so that I don't discover that I'm 4 days stale when I go to recover)
share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

scp does not guarantee file integrity, so a checksum comparison between source and destination would be wise.

You mention your needs are simple, but rsync does not necessarily add complexity and offers significantly more features that will make you feel more comfortable that your synced data is legit.

rsync -ave ssh /your/source/file remotehost:/your/dest/file

If $? (exit status) is not 0 (success), then retry/alert/etc... If you are syncing entire directories, rsync is also much more suited for that, especially if you need to retry on failure, as incremental syncs will be significantly faster with each successive run.

share|improve this answer
add comment

I'm not quite sure how rsync doesn't align with your simple needs.

rsync -avPe ssh user@host:/that/dir /goes/here

if you really want to use scp, though, just loop your scp and test its exit condition.. something like..


#!/bin/bash
STATUS=1
while [ $STATUS -ne 0 ]; do
    echo "scp'ing..."
    scp -r thisstuff/ user@host:/overthere
    STATUS=$?
done

scp will return 0 on success, and > 0 on error.

share|improve this answer
    
Another thing that should be added to the loop was to (1) generate the sha1sum of the file before transfer and (2) within the loop if the status was 0 use ssh to do an sha1sum of the remote file and then exit the loop if the sha1sums were equivalent. –  mdpc Jul 12 '11 at 22:52
    
I posted that more to demonstrate how needlessly complex loading those requirements onto scp would be when rsync basically solves the problem in one command... –  MrTuttle Jul 12 '11 at 22:54
    
An apt demonstration that rsync is the simple option... –  womble Jul 12 '11 at 23:25
add comment

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.