I'm running hardware with no battery backed hardware clock. There is no internet available so no ntp server. I want to be able to reboot the device by cron once a week. Before rebooting, I'd like to save the current time to NVRAM, reboot, and then restore the saved time, and add the number of seconds for typical reboot. I figure this might keep the time reasonably accurate. Any tips on how to make this happen?
At a gross level, you can create a Stop init script to touch a file on /etc (that will happen as it's going down), then look at the timestamp as you're coming up in a separate Start init script, add the required seconds offset, and there you go.
It won't work for power loss (nothing will), it'll never be super-accurate and you probably will never be quite satisfied, but I think that's about as good as it gets.
You don't even have an internal system with internet access/a reasonable time source that you could draw from without the device itself having to reach out over the Internet?
The easy alternatives would be pulling the time from a (USB or serial) GPS or DCF77 (or similar in other regions of the world) receiver and feeding that into a local ntpd instance, respectively connecting a simple battery backed rtc over i2c/ spi or similar free GPIO based pins on the board.
At some point, a x86_64 based router (with its battery backed RTC) becomes attractive.
Thanks. The system is UPS backed for about 24 hours. The system is totally isolated, so no other device or the internet to provide network time. I'm not a linux expert, so not sure how to do this easily. I know what touch does, so that would create a file as of a specific time. Any tips on how to read the modified time of that file on boot, and add, say, 90 seconds to the time, and set the clock?