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've got a Debian Linux-based server that accepts file uploads via scp, and this server tends to get powered off suddenly from time to time. If the power loss occurs shortly after an scp upload has completed, this can result in the uploaded file(s) showing up truncated (or missing) the next time power is restored.

Is there a way to force sshd (or whatever process is writing the uploaded data to disk... I think it is sshd) to call fsync() when the upload is complete, in order to minimize the chance of data loss due to a power outage?

As an example of the kind of thing I'm looking for, this server also accepts file uploads via Samba/CIFS, and I found that adding the following lines to the [globals] section of my smb.conf helps guard against data loss there:

strict sync = yes
sync always = yes

So I'm looking for something analogous, perhaps something that I could put into /etc/sshd_config ?

Thanks!

share|improve this question

2 Answers 2

up vote 1 down vote accepted

No way I know of to make sshd do this, though Kyle's solution is certainly a valid one (assuming you're using keys and an agent, and can stand a few seconds between the upload finishing & the sync request).

If you're paranoid about data loss I suggest investing in a UPS and a RAID card with a battery backup.
If cost is an issue you can mount the target filesystem with the sync option (forces all writes to occur synchronously).

Mounting with sync set will be a a performance hit, but when your transfer is done you know the data is all on disk (subject to the whims of disk controller caches, which if you're using a decent RAID controller may be a noticeable delay - see above :).

share|improve this answer

One of the GNU core-utils is the sync command. So you can just have your upload script ssh in and run that command at the end. There might be something cleaner than that though.

share|improve this answer
    
well done on the new job dude, don't hesitate to call on me for help or whatever ok - I'm strongest on server hardware, ESX/i and FC/FCoE SAN ok. –  Chopper3 Jul 1 '10 at 8:15
    
Thanks Chopper :-) –  Kyle Brandt Jul 1 '10 at 14:20

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.