How to disable main course backup in automated backups?

How to disable main course backup in automated backups?

by Séverin Terrier -
Number of replies: 4
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

I had several problems with my backups, and most of them are now resolved.

But i still have problems whit automated backups, when doing backups of main course, (i think) because there are lot of logs (actual and legacy, from 2 years).

So, what can i do to (simply) disable main course backup, and let automated backups make good backups for all other courses?

I've tried to define next backup date in the futur, with this command :

UPDATE mdl_backup_courses
SET nextstarttime = 1450000000
WHERE courseid = 1;
But it has done nothing good.

I've so also tried to modify latest status, with :

UPDATE mdl_backup_courses
SET laststatus = 1
WHERE courseid = 1;
But still nothing good.

Anybody has a better idea for my problem?

Séverin

Average of ratings: -
In reply to Séverin Terrier

Re: How to disable main course backup in automated backups?

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

Hi,

I've also tried this, to have a startup date before the ending date, a status OK, and a next start time in the futur :

UPDATE mdl_backup_courses
SET laststarttime = 144839000, lastendtime=1448400000, laststatus = 1, nextstarttime=1450000000
WHERE courseid = 1;
But it didn't changed anything, backups directly began with the front page (and still generated errors) sad

After doing more searches, and looking in code, in think i've understood why.

Script moodle/admin/cli/automated_backups.php make this call (line 94) :

backup_cron_automated_helper::run_automated_backup(backup_cron_automated_helper::RUN_IMMEDIATELY);

And in moodle/backup/util/helper/backup_cron_helper.class.php, RUN_IMMEDIATELY (tested line 145) tells to ignore defined next date!

So, i suppose possible solutions would be:

  • in automated_backups.php : remove this parameter
  • in backup_cron_helper.class.php : remove the test on this parameter (line 145)
  • in backup_cron_helper.class.php : add another test (line 145) to avoid course 1

But for that, i will have to modify Moodle's code. And that's something i hardly try to avoid...

So, if someone can confirm, or provide a better solution, it would be helpful.

Séverin

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

Re: How to disable main course backup in automated backups?

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

Hello,

As already explained in french forum, i've used the third solution, by adding a test in moodle/backup/util/helper/backup_cron_helper.class.php. The line 145 is now :

|| ($rundirective == self::RUN_IMMEDIATELY && $backupcourse->courseid != 1) );

And all my backups are OK sourire

Only course 1 (main page) isn't backuped, but it's not really a big problem for me.

The only problem : nextstarttime has been automatically modified by the script (like for all other courses). So, to avoid making backup next time, i've defined a specific cron to modify each day the nextstarttime for course 1, late in the futur. It should so be definetly OK sourire

Séverin


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

Re: How to disable main course backup in automated backups?

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Séverin,

that's correct. Automated backups can be invoked from these 2 callers:

  • automated backups cron task. Then they are called under RUN_ON_SCHEDULE mode, and next-start-times are observed.
  • automated backups cli. Then they are called under RUN_IMMEDIATELY mode, and next-start-times are ignored.

So, while your "hack" is ok,to prevent RUN_IMMEDIATELY to proceed with frontpage (id=1) course, they still can be launched because next-start-times can lead to that (hence your need to create a new cron setting and setting those times in the future all the time).

So, I'd suggest, if you are 100% sure that you don't want a frontpage backup to be triggered ever, to apply for the exception globally and not only for the RUN_IMMEDIATELY case. This can be achieved by putting the condition one level outer, in the very same line (that way it will apply to all the cases):

$shouldrunnow = $backupcourse->courseid != 1 && (($backupcourse->nextstarttime > 0 && $backupcourse->nextstarttime < $now)
                    || $rundirective == self::RUN_IMMEDIATELY);

Or alternatively, I think that's the place I'd use, at the beginning of the loop, with a simple and clean continue, aka:

foreach ($rs as $course) {
    if ($backupcourse->courseid == 1) {
        // We don't want frontpage automated backup ever, skip it.
        continue;
    }
    ...
    ...

Ciao smile

Average of ratings: Useful (3)
In reply to Eloy Lafuente (stronk7)

Re: How to disable main course backup in automated backups?

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

Hi Eloy,

Thanks for your detailed information, it's simpler/better than what i'd done smile

Séverin