How to recreate lost shares from backup of oc_share db table

Several times over the years that we’ve been using ownCloud and Nextcloud, we’ve suffered events that have caused us to lose all share information. What exactly caused these events or why all shares are lost, I don’t know, but I’m willing to believe that it’s something we’ve done incorrectly, probably related to changes in storage that aren’t done properly. That’s not the point of this post. The point is that when such an event happens, and given that we have a complete mysqldump backup of the Nextcloud database oc_share table where we can see all of our old share information, I’m wondering if there is a tool that can process an oc_share table backup and attempt to recreate all shares.

Is such a tool is available?

This aspect of Nextcloud seems to me to be extremely fragile - it’s far too easy to competely lose all share data for all users - and it would be great if there were an automated way to recover from such a disaster.

Well, looking at the NC database, this should somewhat work, if the file IDs in the table oc_share are the same as in oc_filecache. However, this couldn’t be expected to 100% and it could lead to possible disclosure of sentitive information, should the IDs not match or be assinged otherwise in the meantime.

At any rate, the person that would want to write an interpreter for this, would surely have a ton of people on his heels, if this went wrong, which is probably, why the devs didn’t include this from the start.