Script for upgrading Moodle via command line.

Script for upgrading Moodle via command line.

by Daniel Martin -
Number of replies: 7

We have been trying to upgrade from 3.5.1 to 3.5.17 for a while now.  I believe we may have made it more complicated that it should be.  It may be that it is complicated because it's been around a while and there have been customizations, yet we are not sure.

Does anyone have a script they use for upgrading via command line that they would like to share?  Even if it's for another version.

The documentation on Administration via command line - MoodleDocs notes that the script doesn't put the site into maintenance mode, nor backup data.

Thanks,

Daniel

Average of ratings: -
In reply to Daniel Martin

Re: Script for upgrading Moodle via command line.

by Ken Task -
Picture of Particularly helpful Moodlers
There are scripts that do maintenance mode (enable/disable) - in code/admin/cli/

No scripts for full site backup, but easily done (if on Linux - any flavor) the following should work .. you'd have to adjust version/paths:

Called 'bu' and at code root:

# 3.8.8+ (Build: 20210312)
tar -cvf /mnt/data/backup/m38/moodle-code-388+-$(date +%Y%m%d%-H%M%S).tar ../moodle38;
tar -cvf /mnt/data/backup/m38/moodle-data-min-388+-$(date +%Y%m%d%-H%M%S).tar /var/www/moodle38data/filedir;
mysqldump -u root -p'[password]' moodle38 > /mnt/data/backup/m38/moodle388+-db-$(date +%Y%m%d%-H%M%S).sql;
ls -l /mnt/data/backup/m38/;

'SoS', Ken
Sent you direct EMail. smile
Average of ratings: Useful (1)
In reply to Daniel Martin

Re: Script for upgrading Moodle via command line.

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers
You should look at Moosh for doing this sort of thing:
https://moosh-online.com/commands/
Moosh is a set of commands that you can run on the command line to automate Moodle tasks.
Most command line admin type people would also use git for parts of the process I think

[Edit: Oh, and since you are on an older Moodle, also see this thread: https://github.com/tmuras/moosh/issues/370 ]
Average of ratings: Useful (1)
In reply to Justin Hunt

Re: Script for upgrading Moodle via command line.

by Daniel Martin -
Thanks for all the support.

We tried to roll back a snapshot of the server on Hyper-V and it failed, we are now reverting to a backup.
We are currently just testing on a DEV of the server to see how it works, thus nothing is lost. Once we know what we are doing we will do the same on production.

In Moodle in English: Upgrade Moodle Database Now doesn't seem to do anything. I posted an error we had before asking about scripting.  We likely need to clean up many old plugins.  (Thanks Ken for pointing this out)

In reply to Daniel Martin

Re: Script for upgrading Moodle via command line.

by Daniel Martin -
An update:

The more we look into it, the more we realize it may take some time to find all the custom code throughout the site. Also considering starting over and helping teachers move their content to the new one an only add necessary plugins when requested.

Tested uploading backups of courses on a newly installed site and it seems to copy over the content, yet still not sure if there is some content missing because of a missing plugin.

Starting the new site using Git which we hope will make it easier for updates in the future.

Thanks everyone for all the support.
In reply to Daniel Martin

Re: Script for upgrading Moodle via command line.

by Daniel Martin -
Thanks to all the support from various post, and trying once again we were able to update from 3.5.1 to 3.5.17, now we do the same to production. Then see what it takes to upgrade to 3.9

By enabling debug we were able to see two custom plugins causing the upgrade issues. Along with Custom Label and SAML2 not being able to update after the upgrade.

Thanks for everyone's support. I have learned so much about Moodle smile

Here is the details of what we did:

Linux
1. Updated config.php
$CFG->debugusers = '12345';

@error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS!
@ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS!
$CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS!
$CFG->debug = (E_ALL | E_STRICT);

$CFG->noemailever = true; // NOT FOR PRODUCTION SERVERS!

Moodle
2. Enable Debug
a. Site Administration > Development > Debugging
i. Debug messages: Developer
ii. Display debug messages: Yes
iii. Performance info: Yes
iv. Show page information: Yes
3. Update Custom Label
a. Download Course element: Version 3.5.0 (Build 2018120600)
b. Delete the folder /customlabel/js from the zip
c. Remove the /customlabel/type/keypoints folder from the zip
d. Add the keypoint folder to the zip file from /moodle/mod/customlabel/type/
e. Site Administration > Plugins > Install plugins
i. Upload the zip
ii. Press “Install plugin from the ZIP file” button, then “Continue”
iii. Press “Upgrade Moodle database now” button at the bottom of the page.
4. Remove SAML2
a. Re-assigned to SAML2 authentication
SELECT id, username, lastname, firstname, email
FROM `mdl_user`
WHERE `auth` = 'saml2'
i. Reassign to ‘auth’ to ‘manual’
b. Site Administration > Plugins > Authentication > Manage Authentication
i. Disable SAML2 by clicking on the eyeball
c. Site Administration > Plugins > Plugins Overview
i. Unstall SAML2, Continue, Continue
ii. Wait…
iii. Press “Upgrade Moodle database now” button at the bottom of the page.
iv. Uninstall the other SAML2, Continue, Continue
v. Press “Upgrade Moodle database now” button at the bottom of the page.
5. Remove CUSTOM Gmail
a. Site Administration > Plugins > Plugins Overview
i. Uninstall CUSTOM Gmail, Continue, Continue
ii. Wait…
iii. Press “Upgrade Moodle database now” button at the bottom of the page.
6. Remove CUSTOM Mail
a. Site Administration > Plugins > Plugins Overview
i. Uninstall CUSTOM Mail, Continue, Continue
ii. Wait…
iii. Press “Upgrade Moodle database now” button at the bottom of the page.

Hyper-V
7. Snapshot

Linux
8. Run Upgrade Script
wget http://sourceforge.net/projects/moodle/files/Moodle/stable35/moodle-latest-35.tgz
#Backup
mv moodle moodle.backup
#Download
tar xzf moodle-latest-35.tgz
#Config
cp moodle.backup/config.php moodle
#Themes
cp -pr /moodle.back/theme/CUSTOM_adaptable /moodle/theme
#Plugins
cp -pr /moodle.back/mod/bootstrapelements /moodle/mod/botstrapelements
#... not listing them here but we had around 40 folders to copy
#Permissions
#Upgrade
#Permissions

Moodle
9. Install avalible updates.
10. Disable Maintenance mode
Average of ratings: Useful (2)
In reply to Daniel Martin

Re: Script for upgrading Moodle via command line.

by Daniel Martin -
Thanks everyone for your assistance. We decided to start with a fresh copy of 3.9 and manually copy over what was still needed.