At the end of every semester, we have copied our production instance to an archive one (fully functional install, where only instructors/admins would be allowed to go).
Then we have deleted "old courses" from production. Each archive would hold only one semester of courses. Production can be upgraded as usual, with archive instances staying on old moodle versions.
Repeat every semester