Encrypted files not opening after disruption of remote storage

We use remote storage and encryption. Last week the storage went ofline and we could not open our files anymore when it was back again.

I found out that in the database the field encrypted in the oc_filecache table was 0, which seems to mean the file is not encrypted. I update this to 1 and most of the files were opening again.

Some files have multiple versions and they did not open yet. So I searched further and found out that there are records with a value starting with files_version in the path column which have another value the 0 or 1 in the encrypted column (adds 1 for every version). The file itself have the highest value of these versions + 1. As these are nearly 100 files, how can I update these in the simplest way?

And how can I prevent this from happening again?