Regularly write that data to NVM. Con: Saving the state, so that it make sense, must happen in the range of seconds, whereas powerdown is in the range of days. This ratio is very inefficient, as it wears down the NVM unnecessarily and wastes tons of processing cycles.
If you use the built-in EEPROM this isn't so bad as it's rated for something like 1 million cycles. If you write the ENTIRE EEPROM every 5 seconds then it should last at least 1e6 cycles * 5s/cycle = 57 days. If you manage the EEPROM intelligently and only write, say, 8 bytes in sequence then it will last 2048/8 = 256 times as long, or 40 years.
Build the circuit in a manner, where in case of circuit power loss:
a) A certain circuit component continues to power the Arduino for a short "emergency shutdown" period,
b) A certain circuit component triggers the Arduino,
c) This event triggers the routine "save program state to non-volatile memory".
This is coming up regularly in the forum....have a look at this suggested circuit:http://ruggedcircuits.com/html/circuit__13.html
The Gadget Shield
: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons