Performing front-end backups

The Frontend backup function is intended to provide the capability to perform an unattended, timed backup of your site.

[Tip]Tip

Since JoomlaPack 2.0 Stable there is a more efficient way to remotely initiate a site backup. You can use our new JoomlaPack Remote utility for Windows (part of the JoomlaPack Native Tools distribution) to backup your sites right from your desktop, automatically downloading the backup files as well. However, it does not allow for backup scheduling with the same flexibility as cron used with the front-end backup feature does.

The script performs one backup step and sends an HTTP 302 header to force the client to advance to the next page, which performs the next step and so forth. You will only see a message upon completion, should it be successful or not. There are a few limitations, though:

Most hosts offer a CPanel of some kind. There has to be a section for something like "CRON Jobs", "scheduled tasks" and the like. The help screen in there describes how to set up a scheduled job. One missing part for you would be the command to issue. Simply putting the URL in there is not going to work. If you are on a UNIX-style OS host (usually, a Linux host) you most probably have access to a command line utility called wget. It's almost trivial to use:

wget --max-redirect=1000 "http://www.yoursite.com/index2.php?option=com_joomlapack&

view=backup&key=YourSecretKey&format=raw"

Of course, the line breaks are included for formatting clarity only. You should not have a line break in your command line!

[Important]Important

Do not miss the --max-redirect=1000 part of the wget command! If you fail to include it, the backup will not work with wget complaining that the maximum number of redirections has been reached. This is normal behavior, it is not a bug.

[Warning]Warning

Do not forget the double quotation marks which surround the URL. Otherwise the ampersands and other special characters will be interpreted by your shell and cause the backup to fail.

If you're unsure, check with your host. Sometimes you have to get from them the full path to wget in order for CRON to work, thus turning the above command line to something like:

/usr/bin/wget --max-redirect=1000 "http://www.yoursite.com/index2.php?option=com_joomlapack&

view=backup&key=YourSecretKey&format=raw"

Contact your host; they usually have a nifty help page for all this stuff.

Optionaly, you can also include an extra parameter to the above URL, &id=profile_id, where profile_id is the numeric ID of the profile you want to use for the backup. If you don't specify this parameter, the default backup profile (ID=1) will be used. In this sense, the aforementioned URL becomes:

/usr/bin/wget --max-redirect=1000 "http://www.yoursite.com/index2.php?option=com_joomlapack&

view=backup&key=YourSecretKey&format=raw&profile=profile_id"

wget is multi-platform command line utility program which is not included with all operating systems. If your system does not include the wget command, it can be downloaded at this address: http://wget.addictivecode.org/FrequentlyAskedQuestions#download. The wget homepage is here: http://www.gnu.org/software/wget/wget.html. Please note that the option --max-redirect is available on wget version 1.11 and above. At the time of this writing this particular version was not available for the Windows ™operating system.

[Important]Important

Using a web browser (Internet Explorer, Firefox, ...) or wget version 1.10 and earlier will most probably result into an error message concerning the maximum redirections limit being exceeded. This is not a bug. Most network software will stop dealing with a web site after it has redirected the request more than 20 times. This is a safety feature to avoid consuming network resources on misconfigured web sites which have entered an infinite redirection loop. JoomlaPack uses redirections creatively, to force the continuation of the backup process without the need for client-side scripting. It is possible, depending on site size, JoomlaPack configuration and server setup, that it will exceed the limit of 20 redirections while performing a backup operation.

A PHP alternative to wget

As user DrChalta pointed out in this support forum post, there is an alternative to wget, as long as your PHP installation has the cURL extension installed and enabled. For sterters, you need to save the following PHP script as bacup.php somewhere your cron daemon can find it. Please note that this is a command-line script and needn't be located in your site's root; it should be preferrably located above your site's root, in a non-web-accessible directory.

<?php

    /////////////////////
    //Initialize cURL //
    ////////////////////

    $curl_handle=curl_init();

    /////////////////////
    //Set cURL Options//
    ////////////////////

    //The URL to call
    curl_setopt($curl_handle,CURLOPT_URL,
    'http://www.yoursite.com/index2.php?option=com_joomlapack&'.
    'view=backup&key=YourSecretKey&format=raw');

    //TRUE to follow any "Location: " header that the server sends as part of
    //the HTTP header (note this is recursive, PHP will follow as many
    //"Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).
    curl_setopt($curl_handle,CURLOPT_FOLLOWLOCATION,TRUE);

    //TRUE to return the transfer as a string of the return value of 
    //curl_exec() instead of outputting it out directly.
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);

    //////////////////
    //Open the Page  //
    //////////////////

    $buffer = curl_exec($curl_handle);
    curl_close($curl_handle);

    //////////////////
    //Error Message //
    //////////////////

    if (empty($buffer))
    {
        print "Sorry, the backup didn't work.<p>";
    }
    else
    {
        print $buffer;
    }
?>

Where www.yoursite.com and YourSecretKey should be set up as discussed in the previous section.

In order to call this script with a schedule, you need to put something like this to your crontab:

0 3 * * 6 /usr/local/bin/php /home/USER/backups/backup.php

Where /usr/local/bin/php is the absolute path to your PHP command-line executable and /home/USER/backups/backup.php is the absolute path to the script above.

If you set up your cron schedule with a visual tool (for example, a web interface), the command to execute part is "/usr/local/bin/php /home/USER/backups/backup.php".

Thank you DrChalta for this wonderful tip!