Problem

If a scheduled backup is used as the source of a restore, Drupal's cron will always fail on the restored site, and so no further backups (or other cron initiated actions) will occur.

Cause

This happens because scheduled backups are invoked by Drupal's cron.php which sets the Drupal variable cron_semaphore to indicate it is running, and clears it once completed. This is used to prevent multiple cron jobs from executing at the same time. Therefore when Backup and Migrate dumps the database it will include the cron_semaphore variable.

When the database is restored, a row in Drupal's variable table will be created for the cron_semaphore variable. Since the restore is not being done when Drupal's cron is running, no one will delete the cron_semaphore row and so cron will no longer execute.

This situation can be checked by going to Administer->Reports->Status report and manually invoking cron. It will report "Attempting to re-run cron while it is already running." in the status. The Administer->Reports->Recent log entries will also contain the same error entry.

Suggested Solution

It seems that Backup and Migrate's restore should delete the cron_semaphore variable after the restore if it is present (restoring from a manual backup will not have it set). Also, if the option to put the site offline was selected, then the restored site will be offline. It might be helpful to warn the user of this after the restore so they can go and manually put it back online.

If mysql or phpMyAdmin is used to do the restore, the same problem will occur. So it would probably be worth documenting in the help page.

None of this would be necessary if Drupal's core had a better method of determining if cron was running. For example, it could record the start time and a pid of the cron process. If the semaphore and start time indicated cron had been running a long time, then the pid could be used to see if it was really running, and clear the semaphore if not. That way cron would reset itself if the job crashed or a database restore had been performed.

Work Around

If a database is restored and cron will no longer execute, simply delete the cron_semaphor row in the variable table and clear Drupal's cache.

Using phpMyAdmin access your database and browse the "variable" table. Find the row with the "name" of "cron_semaphor" and delete it. Then go to Administer->Site configuration->Performance and click "Clear cached data". To confirm this has fixed the problem go to Administer->Reports->Status report and manually invoking cron. It should report that it completed successfully.

The cron_semaphor variable can also be deleted using the devel module if it is installed.

Comments

TonyT’s picture

Title: cron stops working after a Restore of Scheduled Backup » Cron stops working after a Restore of a Scheduled Backup
whatdoesitwant’s picture

EDIT: I misread, this post concerns manual back-up. Unfortunately I cannot delete it. My apologies.

I use elysia cron. As far as I understand it already deletes cron_semaphore.
I upgraded backup_migrate to version 2.2. I performed a default backup and restore through advanced backup (for quick backup see issue #661728: Quick Backup not working- Fatal Error Message). I was able to run cron manually and everything appears to be in order.

spacereactor’s picture

Can this be add to the document until Backup and Migrate come up a solution. Those using boost module can use the reset crawler & cron_semaphor under boost setting to remove cron_semaphor.

brightbold’s picture

I was having this problem and deleted the cron_semaphore and cron_last rows as instructed in #146551: Reset cron_semaphore when cron is run manually in admin/reports/status (also clearing the cache, disabling Search, and restarting Apache), but could not get cron to run successfully. But when I turned off Backup & Migrate, cron did run. With the module re-enabled, cron is once again hanging.

I had the same cron hanging issue (although not related to a database restore as far as I can remember) previously with Backup & Migrate 6.x-1.2 (#419554: Cron run fails when attempting to create a scheduled backup) and the issue ended up being closed, saying that if you were backing up a very large database you should be using a different backup solution. But I was dealing with a new Drupal install with no nodes, so the database must have been quite small. (I haven't done any more work on that site since then so have never resolved the issue.) I'm wondering if this is a new issue or an old one that just doesn't occur often enough to get good troubleshooting data.

Both sites have been on a development machine running WAMP and use poormanscron, FWIW. If you have any suggestions of additional troubleshooting steps I can take, or information I could provide that would help someone more familiar with the inner workings of cron and Backup & Migrate troubleshoot the problem, please let me know.

ronan’s picture

Status: Active » Postponed (maintainer needs more info)

If cron is just hanging and not triggering any errors (try a manual cron run from the status page to see if there are any errors generated). Then you may need to check your apache logs. I'm not sure what level of logging WAMP has by default or where it keeps it's logs, but often if php dies an error is written to the apache error log.

brightbold’s picture

Haha well since that was a year and a half ago, I can't even remember what sites were having the problem! I use Backup & Migrate on all my sites in both D6 and D7 and haven't had this problem in ages, so I would assume it was resolved long ago.

ronan’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.