Improve the snapshot initialization script to deal with broken links

In case of the {amos_repository} records are manually deleted, the JOIN
statement would not find those records. So in this rare case, we give it
another try.