Sorry to hear of such trials and tribulations.
First, before giving up hope, ask your provider if they make images (which are entire account backups that would include your moodle site) of customer accounts/servers. If they do, find out if there is a image they could restore.
Site might still be a 2.x, but, if you can login, you can do what you probably should have done before attempting and upgrade ... backup the courses ... download those backups.
BTW, it has always been the case that one should do a full site backup ... that's code directory, DB dump, and the data directory, *before* attempting an upgrade.
If 'first' above is not possible, I can only suggest one thing given your last request:
"The simplest solution would be to somehow extract the courses from the
existing database in form that they can be imported to a fresh Moodle
install. However, I have no idea how to do it, let alone if it can even
be done. I do have shell access if needed as well as phpMyAdmin."
The above might be possible if the database isn't frapped ... you say you have shell (ssh), then there is one thing you might be able to try to get your courses backed up.
Use phpMyAdmin and access your DB. Look at the mdl_courses table ... you are looking for course ID numbers. You'll see full name, short names of courses so should be able to associate what course you want to try to backup with an ID number from that table.
Write down those course names and id numbers *** on paper ***.
For purposes of example:
ID Full Name Shortname
4 Build Your Own LAMP Box - short course (byolb) BYOLB
Then ...
ssh into server
Know a path where you can possibly see a file to download ... can't tell you what that is on your system ... might see a path to your home directory in cPanel ... write down that path (in the example below I'll call that '[mydir]] ... in my example, am going to use /home/backup/
change into the code directory (I can't tell you the path) admin/cli/
On my server that is /var/www/html/moodle34/admin/cli/
in there one will see a backup.php file ... that backs up a course (using parameters from the config.php file in the code directory for the DB name, the DB user, and the DB password).
The command to issue:
php backup.php --courseid=[ONEOFTHOSECourseIDSYouWroteDown] --destination=/full/path/to/[mydir]/
So here is an example on a funcioning server.
Course:
4 Build Your Own LAMP Box - short course (byolb) BYOLB
Path: /home/backup/
Command:
php backup.php --courseid=4 --destination=/home/backup/
If your courses are large, it might take some time. Be patient!
If the stars are aligned just right, one might see something similar to the following:
[root@sos cli]# php backup.php --courseid=4 --destination=/home/backup/
== Performing backup... ==
Writing /home/backup/backup-moodle2-course-4-byolb-20171208-2200.mbz
Backup completed.
I can now download the backup file from /home/backup/ with whatever tool I have to download files and hopefully, that course can be restored.
Good Luck!
'spirit of sharing', Ken