Arduino RTC and EEPROM

Hi, I am using an arduino328p, with a DS3231 RTC and a waterflow sensor. The values of the sensor MUST be printed in the arduino all the time the arduino is awake (Serial.print()). Because in anymoment the Arduino will lose connection with the battery (disconecting it by hand), I need the arduino to save in the EEPROM the last value given from the sensor. Then if the value is the same from 19.57 to 20.00 (with the RTC) when I power up the Arduino the EEPROM value and the Arduino must be set to 0. And then all over again.
I've been looking for a solution but after research nothing new.

THANKS

Search 'power fail'

search bar1.PNG

search bar1.PNG

dougp:
Search 'power fail'

search bar1.PNG

The thing is that I have a water flow generator attached to it, so it's not like the power failed, its more that the water is not turning the motor

What are you printing to with Serial.print() that cannot supply power to the arduino?

Nono, when the shower is turned on, the generator creates energy that powers up the Arduino, then, when the shower is turned off the generator does not turn anymore.

thexspand:
Nono, when the shower is turned on, the generator creates energy that powers up the Arduino, then, when the shower is turned off the generator does not turn anymore.

...and the power fails...