Support

Akeeba Backup for WordPress

#38314 Is there a hook to start the backup task via WP Cron ?

Posted in ‘Akeeba Backup for WordPress’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

WordPress version
n/a
PHP version
n/a
Akeeba Backup version
n/a

Latest post by nicholas on Friday, 13 January 2023 06:17 CST

hieudo1802

Hello,

Just purchased Akeeba Backup Pro for Wordpress and I'm wondering if there's a Wordpress hook that I can fire the backup process via wp-cronjob instead of server cron job ?

Thank you in advance.

Hieu Do

nicholas
Akeeba Staff
Manager

I am currently working on this feature. Expect a new release with this feature by February.

That said, it's probably not all that great in practice because of an inherent design issue in WP-CRON per WordPress' own admission (and what we had found through our own implementation of Lazy Scheduling well over a decade ago, before WordPress' WP-CRON feature even existed!):

> As previously mentioned, WP-Cron does not run continuously, which can be an issue if there are critical tasks that must run on time.

What they are saying is that by default WP-CRON only runs when there is traffic to your site. If you schedule a backup for 1am but there is no traffic to your site between 00:30 and 01:45 your backup will not run at 1am. It may not even run at 01:45, since WP-CRON may have to run other tasks. Your backup may start at 5am, or even when traffic is picking up for your site in the morning.

Moreover, the backup is something which cannot complete in a single page load. The scheduled task performs some work, then it's rescheduled for "as soon as possible" re-execution to continue the backup. This needs to happen several times. On a small site that's about 10 times. On a large site this might be 200 or more times (in the backup log file look for "Starting step number" and take the highest number you see in those lines). Each of those rescheduled tasks has to wait for WP-CRON to tell it to execute. This might make the backup take far longer. Think about a 15 seconds backup now taking well over 6 hours. This of course creates data consistency, performance, and reliability issues.

The only way to fix these problems is to follow WordPress' advice to have a CRON job on your server which executes wp-cron.php every minute. This will allow critical tasks (like taking backups, sending time-critical marketing newsletters, etc) to run "on time" (when they are scheduled, plus or minus a few minutes). It will also allow the backup to execute its chain of tasks without big gaps between them. Backups will still be slower than backups taken from the backend or any other scheduling method, but far more predictably so. This also largely solves the data consistency issue.

However, if you're going to set up a CRON job, why not use one of the existing scheduling methods? The answer to that is if you are on a crap host which only offers "pseudo-CRON" where you enter a URL to be accessed periodically. In this case and this case only WP-CRON is your only solution until you move to a decent, cheaper host which offers real CRON jobs and lets you schedule backups far more reliably.

So, yes, we're gonna offer you a WP-CRON integration but don't expect it to be as reliable as any other scheduling method. This is exactly why I was being hesitant about it up until now. I HAD written an identical feature for our Joomla backup software nearly 15 years ago, it WAS used on real world sites and I HAVE seen first hand the inherent problems of "lazy scheduling". In the end of the day, even if everything else goes in the best way possible, you will be taking a backup while your site has a lot of traffic coming to it which will create backup consistency and site performance issues. You want your backups to run when there is little to no traffic on your site so that your backed up data is consistent and you don't make your site appear slow to your visitors.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

nicholas
Akeeba Staff
Manager

I have great news on this front. I completed the work for WP-Cron integration yesterday, shortly after replying to you (I was already at the final verification stage of this feature).I'm already using it on my dev site to take backups. So does our other developer. As far as we can see it works.

We would really like to have someone use this feature on a real world server as well. If you'd please install the developer's release fromhttps://www.akeeba.com/download/backupwp-dev/7-8-0-dev202301131209-rev6d959ed4.html you can help us with that.

Once installed go to wp-admin, Akeeba Backup, and look towards the top of the main area of the page. There is a new link “WP-CRON Schedule”. Click on it and set up your CRON job.

Feel free to write back with any questions or observations you might have.

Thank you in advance!

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!