Context storage to file - partial loss after unexpected shutdown

Running Node Red on a Raspberry Pi 4 with a USB SSD for file storage.
The Raspberry Pi is powered via a small UPS to protect it from short power outages

I use Context Global storage on file to the USD, for approx 50 values numbers, and normally it works without any issue, even in a controlled reboot of the system.

In 2 cases this year there has been long power outage, beyond the capacity of the UPS, causing the Raspberry Pi to shut down and then restart when the power comes back.
In these two cases I have lost 5 to 10 values that very stored using Context Global storage on file.
The values no longer appears in the Context List in the side panel.

As I only have a partial loss I wonder if anyone has any tips on how to minimise (or eliminate) this data loss issue?

Does the pi shut down in a controlled manner?

No, it is not a controlled shut down in case of a longer power outage.
I've thought on ideas to do a controlled shut down if a power outage last more than x minutes, but I would not be able to restart it then unless I'm on site. (installation is in a secondary home).

This ^

Does your UPS signal a safe shutdown or just kill power when it runs out?

Alternatively, you could store data in a database or use a node that writes to file upon change.

Lastly, if all you wish to do in minimise losses, you could tweak the flushInterval

What have you got the flush interval set to?

No, it is a very simple UPS.

I've not set any flush interval so I assume it is the default 30 seconds

Most of the data the is written to "file" are only update on an hourly to daily interval.
Some Context data that were lost had been written long (hours) before the uncontrolled stop of the Raspberry Pi

What node-red version are you using? Also what nodejs version?

What exactly is the USB SDD?
Is other stuff being written to the device?

Currently running Node Red version 3.0.2 and nodes version v16.18.0.
The USB SSD is a "SanDisk 64GB Ultra Fit Unidad Flash, USB 3.2" plugged into the Raspberry Pi.
The USB SSD stores the Node Red Context data and text files with logs written via Node Red.
Log some log files can periodically be updated every 10s but normally is it only a few update per hour, with text appended to the existing log files.

I would at least upgrade to the latest 3.x version of node red, and preferably to 4.x

Ok, I have planned to make a full reinstall of the Raspberry Pi and I’ll upgrade to NR 4