Many tampered files after power failure

After a power failure of my Raspberry I had many tampered files. I had to restore a backup to be able to restart my system. Is there a way to avoid this problem when there is a power failure?

Raspberries need more than most a UPS, if they are not shut down properly, you will often see corrupted files on your sd card, a $20 ‘usb power bank’ from Amazon will often save your day, add a cron job to shut the pi down if you loose have lost your network for an hour or whatever.

Seeing as it is a Pi, stick an (optocouple with a pullup resistor) r’s diode in the raw 5V. supply with a resutor in series and attach the fet to a gpio and you will then have immediate knowledge of a power failure, compute the running time of the powerbank and an orderly shutdown at 95% of that calculation, reset the timer if the power returns.

2 Likes

Hi Dicko, thanks for your help. Any idea where I could find an example of such a cron job?

I would encourage the optocoupler measurement of actual voltage but if power loss also causes network loss, then

*/6 * * * * if [[ ! $(curl -Is  http://www.google.com|head -1) ]];then $(which shutdown) -h 11;else $(which shutdown) -c;fi 

would check every 10 minutes if you can get to google. If no response shutdown in 11 minutes after ‘walling’ everyone. if the network reappears, cancel the shutdown , that cron job should be run by root.

Thanks again dicko!
I appreciate your support!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.