Guides · Migrations

Moodle course restore stuck on pending

The Pulse processing pipeline showing recordings in progress, stuck in processing and ready.

You upload a backup, step through the restore screens, choose Perform restore, and the course sits there unfinished. Sometimes the restore page says it is pending for hours. Sometimes it moves, stops part way, and shows no error at all. This guide covers both. It is about restoring a course. If the backup itself never finished, start with our guide to a Moodle course backup stuck or pending instead.

Menu names are from the Moodle 5.3 documentation.

Why a restore waits

Moodle's setting for background work is called Asynchronous backup/restore, under Site administration > Courses > Backups. The documentation describes it as letting people carry on with other work while a backup or restore is in progress. It has been on for new installations since Moodle 4.4 and for all sites since 4.5.

A background restore is run by an ad hoc task, the asynchronous restore task. Ad hoc tasks are run by cron, which Moodle documents as running every minute, and each cron run handles scheduled tasks before ad hoc ones. So a restore that says pending is usually waiting for cron, waiting behind other queued work, or has started and failed.

One thing finishes later even on a healthy site. Calendar events from activities, such as assignment due dates, are added by a separate cron task a short while after the restore. Restoring several courses at once queues more of these, so the dates can lag behind the content.

Pending or failed: tell them apart

What you see Likely state Go to
Pending, and nothing else on the site is moving either Cron is not running Check 1
Pending, while other restores and backups complete Long queue, or one task holding it Checks 2 and 3
Started, then stopped with no error The restore task failed Check 4
An error naming a user that "will cause conflict" Same username, different person on this site Fixes below
"XML error: not well-formed" An illegal character inside the backup Fixes below
Upload refused as too large Server upload limits Restore a backup that is too large

The checks, in order

  1. Is cron running? Site administration > Reports > System status. Look at when cron last did its work, not only whether it is switched on.
  2. Is something holding the queue? Site administration > Server > Tasks > Tasks running now shows long tasks in progress, such as a large backup.
  3. Is the restore queued? Site administration > Server > Tasks > Ad hoc tasks groups queued tasks by class name. Clicking a class gives a link to run that task now.
  4. Did it fail? The System status report lists failing tasks. The FAQ advice for a restore that stops with no error is to turn on Debugging and run it again, so the error is shown.
  5. Is the version right? A backup restores to the same Moodle version or a newer one. Restoring into an older site can fail.

Checks 1 to 4 need a site administrator. A teacher who sees a restore pending for longer than usual should send the administrator the course name, the backup file name and the time of the request.

Fixes that match each finding

Cron is stopped. Start it with admin/cli/cron.php, the script the documentation says to use.

The queue is long. Run the restore's task from its class on the Ad hoc tasks page, or with admin/cli/adhoc_task.php, which can run a task by id, by class, or only the failed ones. From Moodle 3.9, adhoc_task.php with --execute and --keep-alive keeps running and picks up new tasks as they arrive, so restores do not wait for the next cron cycle.

User conflict. The error appears when the backup and this site each have a user with the same username, but Moodle decides they are different people, for example because the email addresses differ. For the admin account only, Allow admin conflict resolution under Site administration > Courses > Backups > General import defaults renames the backup's admin user. For other users the FAQ gives two routes: make the details match on the site, or edit users.xml inside the backup, then pack it again.

XML error. Usually a character pasted in from elsewhere. The FAQ route is to unzip the backup, find and remove the character, and zip the contents again (the contents, not the folder).

A very large course. Restore it from the command line with admin/cli/restore_backup.php, available to site administrators from Moodle 3.10. It takes the backup file path and the id of the category to restore into.

When a restore will never finish

The Moodle FAQ's last resort for a process stuck "in progress" is to clear its pending records from the mdl_backup_controllers table, after backing up the database. The FAQ writes this up for backups. Treat it as a server administrator's change, on a site with a current database backup, and only after cron has been given time to work through the queue. Then request the restore again and watch it through the checks above.

After it finishes

A restore that completes can still need a look:

  • Sections. If the new course has fewer sections than the backup, the extra ones show as orphaned activities. Raise the number of sections to see them.
  • Dates. Activities and sections move with the start date set at the Schema step. User data keeps its original dates.
  • Roles. Someone who restores a course they cannot otherwise manage is given the Restorers' role in courses, Teacher by default.
Open issues, each with what was observed, the courses affected and an owner

A worked example

At a demo university a learning technologist restores twelve module backups into new courses at 09:00. By 11:00 eight have finished and four say pending.

  • Tasks running now shows one very large backup that has been running since 08:30.
  • The Ad hoc tasks page shows the four restores queued behind it.
  • The administrator runs the queued restore tasks with adhoc_task.php, and all four finish within the hour.
  • Two courses show no due dates in the calendar until the calendar task runs a little later.

Nothing was cleared from the database. The team moves large backups to the evening.

Then check the content

A finished restore says nothing about what the course holds. Old dates, links to nothing and missing files come across with the backup. Bradawl Content Check works with Moodle: it opens a course backup made without user data, runs in your browser and sends nothing anywhere, and lists those leftovers, as the rollover checklist describes. It has been tested on invented data, and no findings is not a sign-off that a course is ready. Download Content Check, or see all the free tools.

Moodle is a trademark of its owner. Bradawl is independent and not affiliated with it.

Related guides

Panopto, Blackboard, Moodle, Canvas and Microsoft Teams are trademarks of their owners. Bradawl is independent and not affiliated with them.