Backup via CLI

Backup via CLI

by Gabriel Fernández -
Number of replies: 7

Hello,

We cannot login to our Moodle. So I'm trying to backup the courses from CLI.

I followed this instructions:

https://moodle.org/mod/forum/discuss.php?d=310227

I was able to extract the courses IDs. But when I run the backup script I see the message:

== Performing backup... ==

And then nothing happens. The file was not created and the bash shows up again.

I also followed this other instructions:

https://docs.moodle.org/38/en/Course_backup#Backup_via_CLI_for_administrators

But I get the following errors:

Status: 404 Not Found
Content-type: text/html; charset=UTF-8
No input file specified.

I appreciate your help

Average of ratings: -
In reply to Gabriel Fernández

Re: Backup via CLI

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hello,

You should really give more information : what's your Moodle version ? And technical details (PHP, DB...) of your host. And an idea of number of courses/users...

And why can't you log on your site? Since when/what (did you change something)? Is everybody concerned, or admin only, which authentication method is/are used?

Because perhaps it will be easier to fix the problem than try to (only) backup courses.

More information you give, more chances we have to help ; and the opposite wink

Séverin
In reply to Séverin Terrier

Re: Backup via CLI

by Gabriel Fernández -
Hi, you are right, I gave no context. 😅

We have Moodle 2.8, and Bluehost updated to PHP 7 a while ago. So we are not able to login. We need to extract courses and resources. So I'm trying to migrate the website to a local Moodle instalation in my Mac. I installed the MAMP version for 2.8 because that one comes with PHP 5.x
But the database is over 800 Mb. So I'm trying to learn how to export and import without corrupting the database, it seems that phpMyAdmin may corrupt the database if it is too big.

So while I figure out how to do that, I wanted to try and download the few courses that we actually need, the platform has almost 200 courses. So I was able to follow the instructions mentioned before, and I got the list of courses with their IDs. But when I try to download any course nothing will happen. The idea would be to import the course to the local MAMP installation.

When it comes to people concerned about it. We only have a couple of professors who really need those resources by the end of next week. But everybody else is working on a new Moodle installation in a new (and better) hosting. All the students are there too.

I am also thinking that as a last resort, I could try and update Moodle all the way up to 3.x. I know is not the best practice, but I guess that would be the final try. I'm leaving that as a last option because the database may get corrupted in the process.

In reply to Gabriel Fernández

Re: Backup via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

'Perfect Storm' situation!   2.8 won't run under PHP 7.0.x and higher ... first version of Moodle that would is 3.0.x.

Suggest backing up what you can before going further ... safest way are 2 command line only tools ... tar and mysqldump .. neither of those use PHP nor old Moodle code no longer compat.

Must have ssh/command line access site and find where code and moodledata is located + DB name, DB user, DB password.   All that info is in config.php of your site.

To backup database with no corruption:

mysqldump -u 'dbuser' -p'dbpass' 'dbname' > moodle28.sql

you replace values in '' above with those seen in config.php

To backup moodledata .. path is in config.php

From your home directory and in ssh:

tar -cvf moodledata.tar /path/to/moodledata

To backup moodle code ... probably in /home/customer/public_html/? Use your cpanel or other tool that can browse files to locate.

From home directory and in ssh

tar -cvf moodle28code.tar /path/to/moodlecode

Download both 'tar' files and the .sql dump to your local machine.

Do that first, then we can figure out rest!

'SoS', Ken

In reply to Gabriel Fernández

Re: Backup via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

Part 2 - once you have those site backups ...

Site restore ... only maybe not with MAMP ... VirualBox with a Linux distro CentOS 6 or Ubuntu vr? that one could use PHP 5.4 or .6 upon which to restore site.

Once on a VB server you control ... git side load to a 2.9.x ... upgrade site via git and cli scripts in code/admin/cli/.   Check site with browser ... backup code/DB ... upgrade via git + scripts to 3.0.highest .... ditto.   Once a 3.0.x, one could try a course backup from the VB site and restore to true server.

Fingers crossed at that point.

'SoS', Ken

In reply to Ken Task

Re: Backup via CLI

by Gabriel Fernández -
Hi,
Thank you so much for all this info.
I will install Ubuntu in VirtualBox and follow your instructions. That was an initial idea, but then I saw that MAMP was pretty easy to use.
I will try the Site Restore instructions.
We don't really need to upload Moodle back to Bluehost, because that account is going to die. Having the resources here with us is sufficient.

I will keep you guys posted if I encounter an issue.
In reply to Gabriel Fernández

Re: Backup via CLI

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hi,

To import large database from a big dump file without problem, you could perhaps use Bigdump script.

Perhaps just check carrefully charset and collation used.

HTH,
Séverin
Average of ratings: Useful (1)
In reply to Séverin Terrier

Re: Backup via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

@Séverin - thanks for sharing a tool that's been needed for a while now!

'SoS', Ken