Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-69358

The 'backup_cleanup_task' task deletes records related to incompleted adhoc tasks

XMLWordPrintable

    • MOODLE_37_STABLE, MOODLE_39_STABLE
    • MOODLE_38_STABLE, MOODLE_39_STABLE
    • master-MDL-69358
    • Hide

      Installation:

      1. "Enable asynchronous backups" - Asynchronous backup/restore admin setting:

        php admin/cli/cfg.php --name=enableasyncbackup --set='1'

      2. Set "loglifetime" to "1" - General backup defaults admin setting:

        php admin/cli/cfg.php --name=loglifetime --set='1' --component='backup'

      Testing instructions:

      1. Create a course.
      2. Navigate to newly created course and click on cog, select 'Backup'. Once you are on 'Course Backup' page, click on 'Jump to final step' button to initiate course backup.
      3. Age the backup controller

        UPDATE mdl_backup_controllers set timecreated = timecreated - (60 * 60 * 24 * 5);
        

      4. Run the CLI cleanup task:

        php admin/tool/task/cli/schedule_task.php --execute='core\task\backup_cleanup_task'

      5. Confirm, that output looks like:

        Execute scheduled task: Clean backup tables and logs (core\task\backup_cleanup_task)
        ... used 5 dbqueries
        ... used 0.0065770149230957 seconds
        Scheduled task complete: Clean backup tables and logs (core\task\backup_cleanup_task)

      6. Run SQL and confirm, that there is at least one record which looks like:

        select id, backupid, operation, type, itemid from mdl_backup_controllers;

        id backupid operation type itemid
        1 402e1ea11823267721eb8770b5e9e949 backup course 4
      7. Run SQL and confirm, that there is at least one record and backupid from step 8 matches with backupid in customdata field which looks like:

        select id, classname, customdata from mdl_task_adhoc where classname like '%asynchronous_backup_task%';

        id classname customdata
        1 \core\task\asynchronous_backup_task {"backupid":"402e1ea11823267721eb8770b5e9e949"}
      8. Run the CLI cleanup task:

        php admin/tool/task/cli/adhoc_task.php -e

      9. Confirm, that there are no errors and output looks like:

        Execute adhoc task: core\task\asynchronous_backup_task
        ... started 06:46:02. Current memory use 44.8MB.
        Processing asynchronous backup for backup: 402e1ea11823267721eb8770b5e9e949
        Backup completed in: 1 seconds
        ... used 681 dbqueries
        ... used 0.49198579788208 seconds
        Adhoc task complete: core\task\asynchronous_backup_task
        Ran 1 adhoc tasks found at Fri, 31 Jul 2020 06:46:02 +0100

      Show
      Installation: "Enable asynchronous backups" - Asynchronous backup/restore admin setting: php admin/cli/cfg.php --name=enableasyncbackup --set='1' Set "loglifetime" to "1" - General backup defaults admin setting: php admin/cli/cfg.php --name=loglifetime --set='1' --component='backup' Testing instructions: Create a course. Navigate to newly created course and click on cog, select 'Backup'. Once you are on 'Course Backup' page, click on 'Jump to final step' button to initiate course backup. Age the backup controller UPDATE mdl_backup_controllers set timecreated = timecreated - (60 * 60 * 24 * 5); Run the CLI cleanup task: php admin/tool/task/cli/schedule_task.php --execute='core\task\backup_cleanup_task' Confirm , that output looks like: Execute scheduled task: Clean backup tables and logs (core\task\backup_cleanup_task) ... used 5 dbqueries ... used 0.0065770149230957 seconds Scheduled task complete: Clean backup tables and logs (core\task\backup_cleanup_task) Run SQL and confirm , that there is at least one record which looks like: select id, backupid, operation, type, itemid from mdl_backup_controllers; id backupid operation type itemid 1 402e1ea11823267721eb8770b5e9e949 backup course 4 Run SQL and confirm , that there is at least one record and backupid from step 8 matches with backupid in customdata field which looks like: select id, classname, customdata from mdl_task_adhoc where classname like '%asynchronous_backup_task%'; id classname customdata 1 \core\task\asynchronous_backup_task {"backupid":"402e1ea11823267721eb8770b5e9e949"} Run the CLI cleanup task: php admin/tool/task/cli/adhoc_task.php -e Confirm , that there are no errors and output looks like: Execute adhoc task: core\task\asynchronous_backup_task ... started 06:46:02. Current memory use 44.8MB. Processing asynchronous backup for backup: 402e1ea11823267721eb8770b5e9e949 Backup completed in: 1 seconds ... used 681 dbqueries ... used 0.49198579788208 seconds Adhoc task complete: core\task\asynchronous_backup_task Ran 1 adhoc tasks found at Fri, 31 Jul 2020 06:46:02 +0100

      One of the reason why backup/restore task can fail is due backup_cleanup_task deletes backupid which are older than loglifetime setting.

      After each fail it gets rescheduled and eventually it re-runs once per day. After 30 days (or any other period set in loglifetime setting) `core\task\backup_cleanup_task` deletes the record from mdl_backup_controllers table as it was created more than 30 days ago. After this adhoc tasks fail with `Can't find data record in database table backup_controllers` error. Since that there is nothing we can do with this adhoc tasks. Everything we have is only backipid, but all other details were deleted.

      We can enhance `core\task\backup_cleanup_task` core task to skip backup_controllers records and logs which have incompleted backup or restore adhoc tasks.

      Steps to replicate (simulate) the issue:
      • Enable async backups.
      • Create a course.
      • Take a backup (initiate).
      • Set loglifetime setting to 1 day.
      • Change your system time to +2 days from now. Actually, we don't need to simulate failing task, it's enough just leave it.
      • Run cleanup task:
      php admin/tool/task/cli/schedule_task.php --execute='core\task\backup_cleanup_task'
      • Check that mdl_backup_controllers was cleaned up.
      • Check that mdl_task_adhoc still has asynchronous_backup_task.
      • Run adhoc task:
      php admin/tool/task/cli/adhoc_task.php -e
      • See how it fails with error "Can't find data record in database table backup_controllers"

            mikhailgolenkov Misha Golenkov
            hdagheda Heena Agheda
            Matt Porritt Matt Porritt
            Andrew Lyons Andrew Lyons
            Anna Carissa Sadia Anna Carissa Sadia
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 21 minutes
                1h 21m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.