WbBackup

Summary: Backup dynamic wiki data (wiki.d, cookbook, ...)
Version: 2008-01-22
Status: Stable
Maintainer: Webbird
Categories: Administration

Questions answered by this recipe

How can I backup my wiki using a browser?

Description

WbBackupΔ allows you to store all the dynamic data in your wiki or wiki field into a zip file and download it in one step. It also allows you to manage your existing backup files. (Which means, you can delete the files you don't need any longer using your browser.)

I wrote this backup recipe because I had some problems using the available ones with my wiki farm. When developing this one, I also added some configuration options I found useful for this task.

Please note that the backup is always done for only one field in a farm, not the whole farm!

For information in German language, please see http://www.webbird.de/PmWiki/WbBackup

Installation

You need to install pclzip (see http://www.phpconcept.net/pclzip/index.php) for this recipe to work, which itself requires zlib to be installed. (See your phpinfo().) Just copy the wbbackup.phpΔ into your cookbook directory, then add a 'pclzip' sub directory and copy the pclzip.lib.php into this directory.

    ../cookbook
      |- wbbackup.php
    ../cookbook/pclzip
               |- pclzip.lib.php

As for the most recipes, you include this one by adding the following line to your config.php or farmconfig.php:

    include_once( "$FarmD/cookbook/wbbackup.php" );

Configuration

Most of the configuration options can be left 'as is', as I tried to set them to comprehensible defaults. Except $wbBackupAction and $wbBackupDelAction, all options can be changed for the whole wiki farm in the farmconfig.php and overridden by the wiki fields by setting them in the field's config.php to different values. This is tested at least for $wbBackupDirs, $wbIgnoreDirs, $wbBackupOverwrite and $wbBackupTrace, but it should work for the others, too.

$wbBackupAction

Default: wbbackup

Can be used to change the action name for the backup. (...URL...&action=wbbackup) Please note that this must be set _before_ including the recipe! So, if you'd like to include the recipe in a wiki farm, you can only change the backup action for the whole farm.

    Example: $wbBackupAction = 'mybackup';

$wbBackupAuthLevel

Default: admin

Can be used to change the authorization level necessary for the backup. Please note: As the backup will be called in a page context, the authorisation level given here will be checked for the current page! That means, if you set the level to 'edit' and a user with edit rights for only one page calls the backup action for this page, he can backup and download all the data! This is not necessarily a security risk, but please remember this when you decide to change the level.

Available settings: read, edit, attr, upload, admin

(Not all make sense...)

    Example: $wbBackupAuthLevel = 'admin';

$wbBackupDelAction

Default: wbbackupdel

Can be used to change the action name for the delete action for backup files. (...URL...&action=wbbackupdel) Please note that this must be set _before_ including the recipe! So, if you'd like to include the recipe in a wiki farm, you can only change the backup action for the whole farm.

You will get a page with all available backup files you can choose to delete.

    Example: $wbBackupDelAction = 'mybackupdel';

$wbBackupDelAuthLevel

Default: admin

Can be used to change the authorization level necessary for the delete action for backup files. Please see $wbBackupAuthLevel for some further advice.

    Example: $wbBackupDelAuthLevel = 'admin';

$wbBackupFileName

Default: wiki-backup-<dd-mm-yyyy>.zip

Name of the ZIP file to create.

    Example: $wbBackupFileName = 'my-wiki-backup.zip';

$wbBackupDir

Default: ./__wiki_backups

Directory where the backup files are stored. The recipe will try to create the directory if it does not exist.

Please note: By default, this directory is located in the current wiki field. (At the same level as the wiki.d directory.) That means, it will be accessible from outside. This is the default, because it is meant that you can directly download the backup file with your browser, without having to switch to your FTP client or such. If you'd prefer to store the backup files outside the directories accessible from the Web, please change this setting according to your needs.

$wbBackupDirs

Default: local, pub, cookbook, wiki.d, uploads

List of directories to backup. As you can see, the names are _relative_ to the wiki base directory.

Please note: You can exlude directories (or even subdirectories) with the $wbIgnoreDirs option described below!

    Example: $wbBackupDirs = array( "local", "pub", "wiki.d" );

$wbBackupFile

Default: $wbBackupDir/$wbBackupFileName

It is not necessary to change this option; you should set $wbBackupDir and $wbBackupFileName instead!

$wbBackupBaseUrl

Default: $ScriptUrl without script file name

Base-URL for the download link. You can change this if your backup directory is located outside your wiki. (But still accessible from the web.)

$wbBackupUrl

Default: $wbBackupBaseURL/__wiki_backups/$wbBackupFileName

Complete download URL. You should prefer to set $wbBackupBaseURL to change the download location. As '__wiki_backups' is hardcoded here, you will have to change this if your backup directory is set to another name.

$wbBackupShowLink

Default: TRUE

Set this to FALSE if you don't want a download link on the backup summary page. (E. g., if your backup files are not accessible through the web.)

    Example: $wbBackupShowLink = FALSE;

$wbBackupOverwrite

Default: FALSE

Set this to TRUE if you wish to automatically overwrite existing backup files. You should prefer to leave this FALSE and delete the files you don't need any longer using the 'wbbackupdel' action.

    Example: $wbBackupOverwrite = TRUE;

$wbBackupTrace

Default: FALSE

Prints some further information about what the recipe is doing to the summary page. Useful only for testing and debugging purposes.

    Example: $wbBackupTrace = TRUE;

$wbBackupIgnoreDirs

Default: pub/skins, pub/guiedit

List of (sub-)directories to skip. Can be used if the data amount is too large. (Most servers kill long running scripts after a while, and only allow a certain amount of memory usage.) The names are _relative_ to the wiki base directory.

    Example: $wbBackupIgnoreDirs = array( "pub/skins", "pub/guiedit", "uploads" );

$wbBackupSendToBrowser

Default: FALSE

Set this to TRUE if you want the recipe to send the ZIP file to the browser automatically. (You will get a download window without having to click on the download link.)

    Example: $wbBackupSendToBrowser = TRUE;

Known issues

An empty window appears when calling the backup action

Most webservers are configured to kill long running scripts after a while (e. g. 30 seconds), and restrict the memory usage to a certain amount (e. g. 8 MB). If your wiki has lots of data (many images/uploads, for example), the script may be killed before it gets done.

The ZIP file created in this case is corrupted and cannot be used.

Please try to except some directories by using the $wbIgnoreDirs option.

The backup seemed to proceed, but I cannot find a ZIP file, or the download link provided doesn't work

Possible reasons:

  • You have set some options (regarding download URLs or paths) incorrectly
  • The directory the backup files are stored is not writable, or it can't be created by the script. Check the path and permissions. (Must be writable.)

Abort pclzip.lib.php : Missing zlib extensions

You need PHP compiled with zlib extensions to use this recipe. See your phpinfo() output before installing this recipe. (There should be a table with caption 'zlib', which gives you some version information.)

Notes

Please feel free to submit your suggestions or questions below!

The recipe is called 'WbBackup' because of "Webbird's Backup". ;)

  • This recipe was last tested on PmWiki version: 2.1.27
  • This recipe requires zlib and the pclzip library to work!

Release Notes

2008-01-17
First release.
2008-01-22
Mod: renamed $wbIgnoreDirs to $wbBackupIgnoreDirs to unify variable names
Fix: Text outside php was sent to browser
2008-10-11
Mod: added error handling for PclZip (print out error message if creating the archive fails)

See Also

BackupPages

Contributors

Webbird

Comments

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.