Answer from @PatrickS :
We faced the same challenge a few years ago and did exactly as @valerio.manenti
suggested.
However, with this implementation, we have unpleasant utilization peaks caused by the HistoryUI module, especially when the history is “full.”
In addition, you have to be careful that no alarms are lost when too many alarms are added within one cycle of the timer.
So it is inevitable to export “too early” to avoid loosing alarms, but this causes some alarms to be exported twice.
For these reasons, we switched to a solution with two queries, which is basically an SQL query.
This has enabled us to significantly reduce the utilization peaks:
(On the left is the implementation with HistoryUI, on the right with queries and manual writing of the file) and also avoid the duplication issues.
Solution is described in this wiki post: How we fixed alarm export issues with SQL queries
