Let's say that someone actually wants the same quiz in two different courses - one might be, for example, a summary of a series of courses with the quizzes all brought together - which is what a couple of these seem to be - what would be the correct way to do this without breaking the upgrade routine?
Invalid context id specified context
This is really not supported. The only case I know where someting like this was possible is in ForumNG, where sam marshall did an amazing hack to make it appear that one forum is shared between two different courses. (We are not proposing to include that bit when we submit ForumNG for inclusion in some future Moodle version.)
To be honest, a better approach is to make a new course "Shared quizzes" which might be a Metacourse, and then enrol all the students from both separate courses in that.