Guides · Migrations

Moodle course backup stuck or pending

A processing queue with items past their expected time marked as stuck

You choose Perform backup, Moodle tells you the backup is under way, and an hour later it still says pending. Nothing is broken in the course. In almost every case the backup is waiting in a queue for something on the server to pick it up. This guide explains the queue, gives the checks in the order that finds the cause soonest, and covers the documented way to clear a backup that will never finish.

Menu names are from the Moodle 5.3 documentation.

Why a backup waits

Course backups in Moodle are asynchronous. You ask for one, and Moodle queues it rather than making the file while you watch. You can keep working while it runs.

  • Moodle 4.4: asynchronous backups are on by default in new installations.
  • Moodle 4.5: they are on for all sites.
  • After 4.5 LTS: synchronous backups are removed, so switching back is no longer an option.

The queued backup is run by an ad hoc task, the asynchronous backup task. Ad hoc tasks are run by cron, the server process Moodle documents as running every minute. Each cron run handles scheduled tasks before ad hoc tasks, so a backup can wait behind other work. A backup that stays pending therefore usually means one of three things: cron is not running, cron is running but the ad hoc queue is long, or the task started and failed.

Course copy uses the same background route, and its troubleshooting advice is the same: check cron is running every minute.

The checks, in order

Check Where What it tells you
1. Is cron running? Site administration > Reports > System status Whether cron and its tasks report errors
2. Is something running now? Site administration > Server > Tasks > Tasks running now Whether a backup or another long task holds the queue
3. Is the backup queued? Site administration > Server > Tasks > Ad hoc tasks Queued ad hoc tasks, grouped by class name
4. Is a task failing? Scheduled tasks list, fail delay and Logs columns A non-zero fail delay marks a failing task; Logs give recent runs
5. Did it stop near the end? The backup progress A stall above 90% with no error points to the course format or server memory

Checks 1 to 4 need a site administrator. A teacher who sees a backup pending for longer than usual should pass it to the administrator with the course name and the time the backup was requested.

Check 1 is the one most often skipped. A process can be switched on and still not have run for hours, so the useful question is when it last did its work.

How fresh each source of information is, with the time each was last read

Fixes that match each finding

Cron is not running. Start it, using admin/cli/cron.php, which the documentation calls the correct script to use. In the Moodle FAQ, running cron is the fix "in most cases" for backups that remain in progress.

The queue is long. Two documented options:

  • Run the backup's ad hoc task now, from its class on the Ad hoc tasks page, or with admin/cli/adhoc_task.php, which can run by id, by class, or only failed tasks.
  • Add ad hoc task processing. From Moodle 3.9, adhoc_task.php with --execute and --keep-alive runs like a daemon, waiting for new tasks instead of exiting.

The cron documentation names automated backups as the worst known offender for building up faster than they are processed, and suggests capping them with the task_concurrency_limit setting. If manual backups queue every night, look at the automated backup schedule first.

The task fails. Read the System status report for task errors. The FAQ notes that a failed H5P content type download can stop a backup.

It stops above 90%. The documentation gives two causes: a non-standard course format, so try replacing it, and too little memory on the server.

The course is very large. Back it up from the command line instead, with --destination to choose where the file goes.

Cancelling a backup that will never finish

The Moodle documentation gives no cancel button for a queued backup. Its documented route has two steps:

  1. Run cron, and give it time to work through the queue.
  2. Only if that fails, clear the pending records for that backup in the mdl_backup_controllers table. The FAQ strongly advises backing up the database before changing it.

Step 2 is a database change, so it belongs with whoever administers the server, on a site that has a current database backup. Afterwards, request the backup again and watch it through the checks above.

Automated backups

For scheduled site-wide backups, the report at Site administration > Reports > Backups shows each course's status. "Unfinished" usually means the job ran out of time or resources, and should complete on the next scheduled run. "Error" means it failed, and the course's backup log says why.

A worked example

At a demo university a module leader requests a backup at 16:00 for a summer rollover. At 17:30 it is still pending.

  • System status reports a cron problem: the cron service stopped after a server patch that morning.
  • The administrator restarts cron. The Ad hoc tasks page shows twelve backups queued.
  • Within the hour the queue is empty and the backup is in the course backup area.

No database change was needed. The team adds "cron is running" to its morning checks.

When the file arrives

Check the file name ends -nu.mbz if it is going anywhere outside the course: our guide to a Moodle backup without user data covers why. If the queue backed up just after an upgrade, the course check after a Moodle upgrade includes cron.

Once you have the backup, Bradawl Content Check can read it. It works with Moodle, opens a backup made without user data, runs in your browser and sends nothing anywhere, and lists the leftovers 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.

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.