Unable to automate backup

Unable to automate backup

by Andre Boulay -
Number of replies: 12

Hello, I've recently inherited the managment of the Moodle Server at our institution and cannot seem to get the automated backup to run. 

Presently running v3.6 and have checked all the appropriate boxes on the automated back up page and have read through the documentation countless times. 

It is as if the backup task fails to create. 

I have a checkmark beside the path but after the backup is supposed to run and  I check the logs, the folder is empty. 
It's running on a Linux server.


I'm left scratching my head on this one.

Any help would be greatly appreciated.

Andre

Average of ratings: -
In reply to Andre Boulay

Re: Unable to automate backup

by Ken Task -
Picture of Particularly helpful Moodlers

From what little info about 'institutions' setup (could be a large implemenation with multiple servers), sounds like the task in the cron job didn't run.

Go to your Moodle admin Scheduled Task ... /admin/tool/task/scheduledtasks.php and look at 'Automated backups' to see when it ran last and when it's scheduled to run again.

Using something that can browse files on your server(s), go to the location of moodledata (found in config.php of code) and in there go to temp/backup/.   See any 0 byte .log files?   See any .log files larger than 0 bytes?   See a bunch of folders with long names?   Change into one of those longnamed folders to see what's there (these are where moodle would build backups of courses).

Also ... there are many Linux flavors and hosting situations ... might be a good idea to share what the OS is .... Ubuntu, CentOS, Debian, RHEL, other?

Am assuming 'institution' would mean hosted inside the 'institutions' network but many have opted to host remotely.   If you host remotely, with whom?  (GoDaddy/InMotionHosting/etc., etc.).

Know it sounds like am asking questions that have nothing to do with your problem, but not true! smile

'SoS', Ken

In reply to Ken Task

Re: Unable to automate backup

by Andre Boulay -

Hello Ken, 

Thank you for taking the time to answer.

I'm affraid I am really a neophyte when it comes to administering Moodle and the learning curve is rather steep right now.

Go to your Moodle admin Scheduled Task ... /admin/tool/task/scheduledtasks.php and look at 'Automated backups' to see when it ran last and when it's scheduled to run again.

This is in the configuration page for the automated backups, yes? 
I set it to run last night but nothing happened.

The server is hosted remotely on Funio.
As for the flavor of Linux, it's running Apache 2.4.46 

I don't believe the scheduled backup task has ever run. 

The text files are all 0 bytes

How can I check to see that it is included in the Cron job?

Andre


In reply to Andre Boulay

Re: Unable to automate backup

by Ken Task -
Picture of Particularly helpful Moodlers

There are quite a few things about a moodle that are outside of the moodle admin interface ... no way around that ... time to learn your platform.

See you are using cPanel ... which is an interface provided by where you host to help customers admin their server ... including web apps like Moodle.

Your screen shot shows you used the cPanel file browser and have found moodledata/temp/backup/ directory.   Note that the log files have a date/time and are all 0 bytes in size.   Date/time indicates when the a backup was run and the fact they are all 0 bytes, indiciates backups did run.

In the moodle configuration of auto backups you said you pointed auto to save to a designated directory ... one had to enter a path to that directory.

What is that path?   If auto backups are working ... which 0 byte and date/time stamps on those files indicate ... the backups would be in the the directory that path pointed to.   Can you see anything of that in cPanel's File Browser?

cPanel initial screen when you first log onto it, does show information about server ... usually one finds server information you might need to know and check in the right column.   I don't use cPanel, but from what I re-call of it, the linux operation system (distribution ... like Ubuntu/CentOS/Debian) and version is shown in that right column.    Sometimes that information makes a difference in what someone might suggest you do.

Apache (2.4.46 version) is your web server software that runs moodle PHP scripts.

You might bookmark/favorite the following to help you learn cPanel provided by Funio

https://www.funio.help/hc/en-us/signin?return_to=https%3A%2F%2Fwww.funio.help%2Fhc%2Fen-us%2Farticles%2F220262248-How-to-log-in-to-your-cPanel-account

There should be an icon for Cron Job in cPanel.   Have you ever visited that?  Set up the cron job for the Moodle?

Not all cPanel's are the same .. much depends on what is available in a cPanel upon what package customer leased.   Again, right column when first logging onto cPanel should have what that is.

Again ... I do not host with your provider, so specific questions concerning your site setup should be directed to your provider help desk.

'SoS', Ken


In reply to Ken Task

Re: Unable to automate backup

by Andre Boulay -
Thank you again Ken...

The plot thickens... the directory to which the path points to has an old backup dating from last summer but nothing else.
From what I understand, this was run manually. 
*Sauvegarde* is the directory to which the automated backup points to.

Apart from setting the path in Moodle and setting up the Cron job in C-panel, do I need to edit the cron.php file or anything else manually?

I get the feeling that I've connected all the dots but one and because of this, nothing happens.



I have setup a Cron job set but I may be missing something... 
(Sorry for the French, below are the two Cron jobs that are supposed to run)


Below is the actual directory where the Cron job lives... last modified 2019...
I recently changed the script on the first line of the Cron jobs listed above.
(It was running every hour and not every minute like recommended) 
The second Cron job listed (above) I created as it didn't exist. Last modified a few days ago.
One course runs on v3.8, the rest of the courses are on v3.6



Thank you again...
Andre
In reply to Andre Boulay

Re: Unable to automate backup

by Ken Task -
Picture of Particularly helpful Moodlers

The backup file you found was not created by Moodle.  Filename indicates it is a database dump (the sql in filename) and gunzipped (.gz).

You do not need to edit any moodle code file ... from your screen shot of cPanel set ups of cron, both look like they are entered correctly ... but here again, I don't host where you host!!!! :|

Ahhhhh, but in m36 code/admin/cli/ where the cron.php file you've pointed to correctly for running the script, there is an error_log file.   View it's contents using cPanel's File Browser.   Don't edit ... just view.

Think there could be a clue in there about automated backups failing.

'SoS', Ken


In reply to Ken Task

Re: Unable to automate backup

by Andre Boulay -

We're moving forward I think...

I viewed the file. The most recent log dates back to January. After that, nothing.

[22-Jan-2021 15:00:03 America/Toronto] Default exception handler: Exception : syntax error, unexpected '?' Debug: 
Error code: generalexceptionmessage
* line 183 of /filter/embedquestion/filter.php: ParseError thrown
* line 286 of /lib/filterlib.php: call to filter_manager->make_filter_object()
* line 1576 of /lib/pagelib.php: call to filter_manager->setup_page_for_globally_available_filters()
* line 677 of /lib/pagelib.php: call to moodle_page->initialise_theme_and_output()
* line 864 of /lib/pagelib.php: call to moodle_page->magic_get_theme()
* line 65 of /admin/tool/analytics/classes/task/predict_models.php: call to moodle_page->get_renderer()
* line 105 of /lib/cronlib.php: call to tool_analytics\task\predict_models->execute()
* line 67 of /lib/cronlib.php: call to cron_run_inner_scheduled_task()
* line 61 of /admin/cli/cron.php: call to cron_run()

In reply to Andre Boulay

Re: Unable to automate backup

by Ken Task -
Picture of Particularly helpful Moodlers

Unfortunately, cPanel systems don't have an applet or utility to test the running of a cron job.   Do you have a terminal icon in cPanel?   That's command line to your server.   If you do, you could get into terminal and then use the cron job as you entered it on the command line to see if it really executes or errors.   Error would be to that error_log file in code/admin/cli/

In looking at that error log output see that it says several things ...

embedquestion parse error points to a question in question bank?
There is also a reference to analytics prediction models (is analytics models
defined or in use? Can you turn that off?

If you note it does point to an 'inner scheduled task' ... so maybe disable that scheduled task?    Guess.

Do know that a scheduled task that's part of the overall cron job run can kill the cron job at that point and all that follows don't run.

'SoS', Ken


In reply to Ken Task

Re: Unable to automate backup

by Andre Boulay -
Haha.... progress... I poked around the terminal and determined that the Cron job was not running because the path was not the correct one.
You da man Ken! Thank you!!!
Andre  

In reply to Andre Boulay

Re: Unable to automate backup

by Andre Boulay -
Am I correct in assuming that if the Cron job doesn't go through, the automated backup will not run as scheduled?
In reply to Andre Boulay

Re: Unable to automate backup

by Ken Task -
Picture of Particularly helpful Moodlers

Some more poking around is needed ..

When you run the main cron successfully, the end will say this:

Ran 0 adhoc tasks found at Wed, 31 Mar 2021 10:49:49 -0500
Cron script completed correctly
Cron completed at 10:49:49. Memory used 33.2MB.
Execution took 0.557945 seconds

It's not that Moodle never tries to run autobackup, but rather, jobs that don't complete for some reason get recorded in adhoc_task to pick up where it left off when it didn't complete.

Since you have terminal ...

cd /path/to/moodlecode/admin/tool/task/cli/ (note that's command line)

in there: schedule_task.php

Help on that ... /path/to/correct/php schedule_task.php

Add --list                List all scheduled tasks

php schedule_task.php --list |grep automated_backup_task

above searches for automated_backup_task

will show something like:

\core\task\automated_backup_task                   50 * * * * *      Wednesday, 31 March 2021, 9:50 AM        Wednesday, 31 March 2021, 10:50 AM

Warning; if your autobackups have been stuck, running anything that forces autobackups might be pretty intensive and take a long time.

But, one has to get it to finish ... I've had to use 'nohup' (no hang up) command in front of the php command execution and an & at end to put a stuck thang executing in the background until completed.  Doing that made server slow but ....

Looks like:

nohup php [command with options] &

That puts the command in background and logs to a file at location and allows you to escape from that command in the shell.  Otherwise, one would have to leave that ssh session open and running to finish.

'SoS', Ken

In reply to Ken Task

Re: Unable to automate backup

by Andre Boulay -

I get this as ouput when either of the cron jobs run: 

*but sometimes I get other output... for example:


Is this because the Cron job is tidying up behind all the happenings within Moodle?
(I'm sorry it's an obvious question; I'm new to all of this)


When I try and add the --list argument to schedule_task.php I get this:


If the scheduled backups never ran would I get output like this?

I tried looking at the schedule_task.php and the lines don't correspond to what's inside the file.



In reply to Andre Boulay

Re: Unable to automate backup

by Ken Task -
Picture of Particularly helpful Moodlers

First screen shot does show cron.php executed completely.   Good!

Second screen shot does show an adhoc_task was seen and executed ... the tail end of that shows main cron and the scheduled_task completed successfully, right?   Scheduled task have a time to run of their own.  May not run every time you run cron.php

Now think about the 3rd ... when issued *in-correctly*, output might show errors on lines ... but look at what you issued the running of the script again ...

Is there a php in front of the moodle php script?

The cli php scripts in moodle are not executable by themselves ...

To run them: /path/to/php-cli/php then the name of the script.

Come on now ... first time or not ... sometimes one won't be getting help ... step back ... *thimk*!   (no spelled it right!)

I don't like long paths ... too prone to typo or missing a directory  .... or just plain stupid!  (yeah, I'm stupid sometimes!)   So I change into directories where the cli scripts reside so I can issue giving a shorter command ...

'SoS', Ken