# What is the solution to the loss of data by interrupting the flow of electricity?



## spring_64 (Nov 1, 2017)

Sometimes FreeBSD has problems such as loss of hard disk data or it cannot boot,... when the flow of electricity interrupt.

what is your suggestion to avoid these problems?
Thanks


----------



## SirDice (Nov 1, 2017)

It's called a UPS, not to be confused with the parcel mover of the same name.

https://en.wikipedia.org/wiki/Uninterruptible_power_supply

That will allow the system to continue to run for a certain amount of time. Small interruptions are avoided, bigger ones allow the system enough time to properly shutdown cleanly.


----------



## PacketMan (Nov 1, 2017)

That depends on the your up-time requirement.  If you want three nines (99.9%) go buy a cheap UPS.  If you want nine nines (99.9999999%) up-time go buy a continuous-duty grade RUPS (Rotary UPS = generator + 1 ton flywheel + electric motor + clutch + diesel engine) system.


----------



## spring_64 (Nov 1, 2017)

Thank you for your replies.

UPS is a good idea, but what is your idea about some configuration in system?. for example  I found that the `/` partition should mount read only. I have no idea is this method is good or not and I cannot found the other solutions yet.


----------



## SirDice (Nov 1, 2017)

spring_64 said:


> for example I found that the  / partition should mount read only.


That will prevent some file system corruption but you can't mount _everything_ read-only, I'm assuming you want to be able to actually write files in your home directory for example.

This problem isn't specific to FreeBSD, _any_ file system on _any_ OS can get corrupted if you pull the plug at the 'right' time. Even ZFS can get really messed up that way. You can only manage the effects to some extend. ZFS for example has very good "auto heal" capabilities and it'll be a lot more resilient to "unfixable" corruptions. But even that can only do so much. If it happens often enough there will be a time when ZFS's healing won't be able to fix things.


----------



## PacketMan (Nov 1, 2017)

I have not bought a UPS yet. Keep meaning to, but life gets in the way of life.  I would like to have a system where I can install a port on FreeBSD so that when the UPS battery gets down past the 'low' threshold, it sends a signal/message to FreeBSD (via said port), and then FreeBSD issues a `shutdown -p now` or a series of commands via a script if I preferred.  But so far it seems like any existing ports use a serial cable which I really can't be bothered with. So for now I would just use my backups if the requirement arises.

I know the OS can shut itself down with a momentary press of the power button, so I might try searching for a supported motherboard with a remote power button connector, and a UPS that has a relay it can 'pulse' during low battery, and pulse again when the AC comes on.  This would be preferred actually.


----------



## rotor (Nov 1, 2017)

PacketMan said:


> ...  But so far it seems like any existing ports use a serial cable which I really can't be bothered with. .....



I am currently using the Network UPS Tools (sysutils/nut) port.  It communicates with the Cyperpower UPS via USB cable.


----------



## tankist02 (Nov 1, 2017)

I had data losses during power interruptions with UFS, while ZFS did not have that problem.


----------



## Eric A. Borisch (Nov 1, 2017)

PacketMan said:


> I have not bought a UPS yet. Keep meaning to, but life gets in the way of life.  I would like to have a system where I can install a port on FreeBSD so that when the UPS battery gets down past the 'low' threshold, it sends a signal/message to FreeBSD (via said port), and then FreeBSD issues a `shutdown -p now` or a series of commands via a script if I preferred.  But so far it seems like any existing ports use a serial cable which I really can't be bothered with. So for now I would just use my backups if the requirement arises.



Check out sysutils/apcupsd for working with APC UPSes, including USB models.


----------



## spring_64 (Nov 2, 2017)

SirDice said:


> That will prevent some file system corruption



Would you please explain it more?
I mean what is the disadvantage of this method?

Thanks


----------



## SirDice (Nov 2, 2017)

spring_64 said:


> Would you please explain it more?


Filesystem corruption only happens when the power goes out during a _write_ action. 



> I mean what is the disadvantage of this method?


Well, it's read-only. So you can't write to it. This would make updating a bit trickier as you need to remount the filesystem before you can update.


----------



## spring_64 (Nov 2, 2017)

Many thanks for wasting your time to help me to find the best soloution,

I came to the conclusion that the hardware solution is UPS and if we do not have UPS, it is better to use ZFS instead of UFS. And if updating was not important for us we can mount / partiton.

If you have any other idea, I would appreciate it.


----------



## wolffnx (Nov 2, 2017)

maybe I'am wrong,but this sysctl settings dont sync the data to disc every x seconds?


```
kern.metadelay
kern.dirdelay
kern.filedelay
```

the defaults are

```
kern.metadelay: 28
kern.dirdelay: 29
kern.filedelay: 30
```


----------

