I did see a few posts a while ago about saving variables to eeprom when the power goes down, but I didnt see actual circuits or sketch.
I am using this ciruit ( schematic ) on my embedded projects, any suggestions for improvements welcome. It works for brown outs too.

The digital transistor monitors when the DC input drops below about 8 volts ( you can reduce the zener voltage if using a lower input voltage )
The 470 mFD cap supplies enough power to write to eeprom when the power goes ( or drops low )
The collector is connected to a pin on the ATmega - which should be set for an input with pull-up.
#include <EEPROM.h>
int DCgone = 5;
int unsaved= HIGH;
int DCgoneState= LOW;
then include in void () setup ;
XH = EEPROM.read (1); // XH etc are the variables we stored at brown out/power down last time
XT = EEPROM.read (2);
XU = EEPROM.read (3);
XC = EEPROM.read (4);
NH = EEPROM.read (5);
NT = EEPROM.read (6);
NU = EEPROM.read (7);
NC = EEPROM.read (8 ) ;
pinMode ( DCgone, INPUT );
digitalWrite(DCgone, HIGH); // sets pullup resistor
void loop()
{
DCgoneState = digitalRead ( DCgone );
if ( DCgoneState == LOW )
{
************* Run your loop here ************* }
else {
if ( unsaved == HIGH ) { // we only want to save to eeprom once when power fails
writeeeprom ();
unsaved = LOW;
}
}
} //end of loop
void writeeeprom () {
EEPROM.write(1,XH);
EEPROM.write(2,XT);
EEPROM.write(3,XU);
EEPROM.write(4,XC);
EEPROM.write(5,NH);
EEPROM.write(6,NT);
EEPROM.write(7,NU);
EEPROM.write(8,NC);
}