5

This is just a general question into how the Akeeba backup system works when called from a cron job.

I have traced the coded as much as I can and understand that its called from the front end and then starts the backup from the back end and then redirects the browser back to the step function which checks where the backup is up to.

My question is, how does the step function know where it is up to? How does the server keep processing the backup when the browser has been redirected?

I have crawled the web trying to find information on how this actually works and can't find any. any held or explanation would be greatly appreciated.

Thanks

Lee

  • 1
    You should direct that question to Nicholas, Akeeba developer. I've seen him here, on JSX. – Mikan Jan 24 '16 at 23:06
  • Thanks Mirko, is there a way to tag a user here that you know of? – Lee Wiggins Jan 24 '16 at 23:08
  • 1
    @LeeWiggins you can at-mention me using at-sign nikosdion (@nikosdion) any time you want to get my attention here or on GitHub. – nikosdion Jan 26 '16 at 10:17
8

I am the developer of Akeeba Backup. There are two different CRON scripts supplied with Akeeba Backup Professional.

The recommended method is using the native CRON script which bypasses the web server entirely and runs the backup process essentially as a standalone PHP command line application. But that's not the object of your question.

The legacy backup method uses a special front-end URL indeed. The first URL you hit starts a backup using a specific profile and records that in the database under a specific Backup ID. Some backup work runs. At this time the backup engine state is serialized and committed to temporary storage. An HTTP redirection is issued. When you hit the new URL the backup engine state is read from the temporary storage, unserialized and the backup process resumes. This serialization/redirection/unserialization dance continues until the backup is complete.

First of all, this does not really happen by calling the back-end of the application. Both the front-end (legacy remote backup) and back-end backup controllers implement a similar strategy. The only difference is that the front-end issues HTTP redirections whereas the back-end returns a JSON object for the client-side Javascript to process and decide whether to run the next backup step. The not-so-secret sauce is in the backup engine itself which is stored in the back-end directory of the component, I guess that's what you were trying to trace.

Second and most important is understanding why that works, at all. Because of the serialization/unserialization the internal backup engine state is preserved through the redirection. The trick is that the backup engine uses a Factory object with support for serialization and unserialization. I have blogged about it in October 2009 at my site, dionysopoulos.me. Search Google for "A serializable PHP5 Factory pattern" on my site.

That serializable factory is exactly how the backup engine knows where the backup is up to every single time you resume the backup on a new page load. You are welcome to use this code on your projects implementing a long running process.

  • Firstly, Thank you very much for your detailed answer! It clears up a lot of questions. I will have a look at your blog post and read right through that. Secondly, thanks very much for your permission to use the code, I will check it out for my application. – Lee Wiggins Jan 25 '16 at 9:15
  • The other thing I meant to mention was it would be fantastic if you have any further info on doing it via command script as you mention. – Lee Wiggins Jan 26 '16 at 8:14
  • Cheers! The command line script is much more straightforward. Since you don't have to worry about timeouts under CLI you can run the backup steps one after another. So the CLI script simply runs the start task once and the step task until it's done, then quits. FYI the CLI app uses Joomla!'s JApplicationCli to bring an executable Joomla! environment in CLI. It's one of Joomla!'s hidden secrets ;) – nikosdion Jan 26 '16 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.