Hi V.
It’s funny, I just wrote a post on the same topic.
How does work your script exactly ? What do you need to fix in the database after a restore ?