error/cannot_precheck_wrong_status while restoring good backup files programmatically

error/cannot_precheck_wrong_status while restoring good backup files programmatically

by Perry Way -
Number of replies: 3

A few years ago I made some CLI scripts to backup courses at the end of each of our terms, then delete them from moodle. That system works fine. All files are created without errors and every backup file ever made to date will restore properly, interactively.

We have had to do a few spot-restores of courses so that instructors can get information they need, and then we archive them again. So we do those course restores interactively. Not a problem.

Now, the Dept of Education is coming and the school needs more detailed data on grades historically than can be found in the final course grades. We store the course grades in our SMS system, but not the individual items that make up each grade. Those details are only in these backups since the courses have been removed from Moodle, and there are thousands of these backups.

As you can imagine, having someone manually restore thousands of backup files is very time consuming. So I have written a program to automatically restore files. But it is erroring with "cannot_precheck_wrong_status" right after I call for the the restore controller to precheck.

Here's a snip of my code where the error occurs. The error happens on the line $controller->execute_precheck();

    // Restore backup into course
    echo "creating restore_controller\r\n";
    $controller = new restore_controller($shortname, 
                                        $courseid, 
                                        backup::INTERACTIVE_NO, 
                                        backup::MODE_SAMESITE, 
                                        2,
                                        backup::TARGET_NEW_COURSE);
    echo "executing controller precheck\r\n";
    $controller->execute_precheck();
    echo "executing controller plan\r\n";
    $controller->execute_plan();
    echo "destroyng controller\r\n";
    $controller->destroy();


I am looking for ideas on how to cross this bridge. The Dept of Education is coming and the bosses are pressing me for an ETA on when I'm going to have this fixed so they can prepare their report data they need.


Average of ratings: -
In reply to Perry Way

Re: error/cannot_precheck_wrong_status while restoring good backup files programmatically

by Perry Way -

One post I read alluded to some setting that needs to be set (or reset in this case) properly in the moodle_backup.xml file so I'm enclosing the first backup's file in this post in case that helps me getting help! smile


In reply to Perry Way

Re: error/cannot_precheck_wrong_status while restoring good backup files programmatically

by Perry Way -

I have verified that the .xml file issue raised by another post is not related to my issue at all. 

I have also figured out that the status of the restore controller is not at the status it should be, which is why the restore is failing.

Looks like the status value of the controller is 200, or STATUS_REQUIRE_CONV, and should be 600 or STATUS_NEED_PRECHECK.

Here is the output of my debug, which shows also the print_r() output of the restore controller, in case this helps anyone who is attempting to help me.

restore_controller Object
(
    [tempdir:protected] =>
    [restoreid:protected] => 87efb5fda391b5bfe1cdff7600944942
    [courseid:protected] => 2194
    [type:protected] =>
    [format:protected] => unknown
    [interactive:protected] =>
    [mode:protected] => 40
    [userid:protected] => 2
    [operation:protected] => restore
    [target:protected] => 2
    [samesite:protected] =>
    [status:protected] => 200
    [precheck:protected] =>
    [info:protected] =>
    [plan:protected] =>
    [execution:protected] => 1
    [executiontime:protected] => 0
    [checksum:protected] =>
    [progress:protected] => core\progress\none Object
        (
            [lastprogresstime:protected] =>
            [count:protected] =>
            [descriptions:protected] => Array
                (
                )

            [maxes:protected] => Array
                (
                )

            [currents:protected] => Array
                (
                )

            [parentcounts:protected] => Array
                (
                )

        )

    [logger:protected] => error_log_logger Object
        (
            [level:protected] => 30
            [showdate:protected] =>
            [showlevel:protected] =>
            [next:protected] => file_logger Object
                (
                    [fullpath:protected] => C:\Websites\moodledata_archives/temp/backup/87efb5fda391b5bfe1cdff7600944942.log
                    [fhandle:protected] => Resource id #1100
                    [level:protected] => 30
                    [showdate:protected] => 1
                    [showlevel:protected] => 1
                    [next:protected] => database_logger Object
                        (
                            [datecol:protected] => timecreated
                            [levelcol:protected] => loglevel
                            [messagecol:protected] => message
                            [logtable:protected] => backup_logs
                            [columns:protected] => Array
                                (
                                    [backupid] => 87efb5fda391b5bfe1cdff7600944942
                                )

                            [level:protected] => 30
                            [showdate:protected] => 1
                            [showlevel:protected] => 1
                            [next:protected] =>
                        )

                )

        )

)


In reply to Perry Way

Re: error/cannot_precheck_wrong_status while restoring good backup files programmatically

by Perry Way -

I figured out the problem. It was programmer stupidity. smile I somehow got my wires crossed and was passing a null value for one of my parameters and once I solved that, then the restore controller worked. Problem solved.