Thanks everyone for your assistance. We decided to start with a fresh copy of 3.9 and manually copy over what was still needed.
Installing and upgrading help
Script for upgrading Moodle via command line.
Tutu temu bu zawrjena. Woni móža tu dale wotmołwić.