Not logged in. · Lost password · Register
Forum: General Discussion Plugins RSS
Backup Plugin Feedback
Trying to garner some feedback on the Backup Plugin
PDD #1
Member since Jul 2006 · 68 posts
Group memberships: Members
Show profile · Link to this post
Subject: Backup Plugin Feedback
Hi Folks,

I was wondering if anyone here has the Backup Plugin installed and if it works for them? Ive tried it on three versions of Dokuwiki now (including the latest) and thus far it has never worked for me. I am curious as to how widely used the plugin is.

Regards,

Dave
Avatar
andi (Administrator) #2
Member since May 2006 · 747 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I never used it, but "it doesn't work" isn't a very helpful problem description. Why don't you tell us what happens and what you expected to happen?
Read this if you don't get any useful answers.
awagner #3
Member since Nov 2007 · 14 posts
Group memberships: Members
Show profile · Link to this post
see here. (about the backup plugin using shell_exec intead of php's on-board weapons).

(I'd very much like to have that working since when I log on as ftp user, I cannot access some files and folders that are only accessible to wwwrun/php, so I can't even back up the wiki by ftp unless I reset all ownerships.)

And sorry for double posting but I thought it would be good to have backup plugin feedback in one place.

Andreas
awagner #4
Member since Nov 2007 · 14 posts
Group memberships: Members
Show profile · Link to this post
Subject: my version for 2008-05-05 without shell_exec
Hi all,
I have worked over the backup tool plugin to get rid of the calls to shell_exec. Along the way, I have updated my dokuwiki install and made sure my backuptool would work with the current version as well.
(I have made some adjustments in the lang folder as well, but I suppose you can figure these out yourselves.

<?php
/**
 * Backup Tool for DokuWiki
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Terence J. Grant<tjgrant@tatewake.com>
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
if(!defined('DOKU_INCLUDE')) define('DOKU_INCLUDE',DOKU_INC.'inc/');
require_once(DOKU_PLUGIN . 'admin.php');
require_once(DOKU_INCLUDE . 'TarLib.class.php');

/**
 * All DokuWiki plugins to extend the admin function
 * need to inherit from this class
 */
class admin_plugin_backup extends DokuWiki_Admin_Plugin
{
var $state = 0;
var $backup = '';

    /**
     * Constructor
     */
    function admin_plugin_backup()
    {
        $this->setupLocale();
    }

    /**
     * return some info
     */
    function getInfo()
    {
        return array(
            'author' => 'Terence J. Grant, Andreas Wagner',
            'email'  => 'tjgrant@tatewake.com, andreas.wagner@em.uni-frankfurt.de',
            'date'   => '2008-07-04',
            'name'   => 'Backup Tool Plugin',
            'desc'   => 'A tool to backup your data and configuration.',
            'url'    => 'http://tatewake.com/wiki/projects:backuptool_for_dokuwiki',
        );
    }

    /**
     * return sort order for position in admin menu
     */
    function getMenuSort()
    {
        return 999;
    }
   
    /**
     *  return a menu prompt for the admin menu
     *  NOT REQUIRED - its better to place $lang['menu'] string in localised string file
     *  only use this function when you need to vary the string returned
     */
    function getMenuText()
    {
        return 'Backup Tool';
    }

    /**
     * handle user request
     */
    function handle()
    {
        $this->state = 0;
   
        if (!isset($_REQUEST['cmd'])) return;   // first time - nothing to do

        if (!is_array($_REQUEST['cmd'])) return;

        $this->backup = $_REQUEST['backup'];

        if (is_array($this->backup))
        {
            $this->state = 1;
        }
    }

    /**
     * output appropriate html
     */
    function html()
    {
        global $conf;

        if ($this->state == 0)
        {
            print $this->plugin_locale_xhtml('intro');

            ptln("<form action=\"".wl($ID)."\" method=\"post\">");
            ptln('  <input type="hidden" name="do"   value="admin" />');
            ptln('  <input type="hidden" name="page" value="'.$this->getPluginName().'" />');
            ptln('  <input type="hidden" name="cmd[backup]" value="true" />');
            print '<center><table class="inline">';
            print '    <tr><th> '.$this->getLang('bt_item_type').' </th><th> '.$this->getLang('bt_add_to_archive').' </th></tr>';
            print '    <tr><td> '.$this->getLang('bt_pages').' </td><td><input type="checkbox" name="backup[pages]" checked/></td></tr>';
            print '    <tr><td> '.$this->getLang('bt_old_revisions_of_pages').' </td><td><input type="checkbox" name="backup[revisions]" checked/></td></tr>';
            print '    <tr><td> '.$this->getLang('bt_meta_data_subscriptions').'</td><td><input type="checkbox" name="backup[subscriptions]" checked/></td></tr>';
            print '    <tr><td> '.$this->getLang('bt_media_files').' </td><td><input type="checkbox" name="backup[media]" checked/></td></tr>';
            print '    <tr><td> '.$this->getLang('bt_wiki_acl_user_config').' </td><td><input type="checkbox" name="backup[config]" checked/></td></tr>';
            print '    <tr><td> '.$this->getLang('bt_templates').'</td><td><input type="checkbox" name="backup[templates]" /></td></tr>';
            print '    <tr><td> '.$this->getLang('bt_plugins').'</td><td><input type="checkbox" name="backup[plugins]" /></td></tr>';
            print '</table>';
            print '<br />';
            print '<p><input type="submit" value="'.$this->getLang('bt_create_backup').'"></p></center>';
            print '</form>';
        }
        else
        {
            print $this->plugin_locale_xhtml('outro');

            //remove previous backups
//            shell_exec("rm -rf backup*.tar");
//            shell_exec("rm -rf backup*.tar.bz2");
            foreach(glob("backup*.tar") as $fn) unlink($fn);
            foreach(glob("backup*.tar.gz") as $fn) unlink($fn);
            foreach(glob("backup*.tar.bz2") as $fn) unlink($fn);

            $finaldate = date('Ymd-His');
            if(extension_loaded('bz2'))         $finalfilename = 'backup-'.$finaldate . ".tar.bz2";
            elseif(extension_loaded('zlib'))     $finalfilename = 'backup-'.$finaldate . ".tar.gz";
            else                     $finalfilename = 'backup-'.$finaldate . ".tar";
           
            $finalfile = DOKU_INC.'/data/tmp/'.$finalfilename;
            $Archive = new tarlib($finalfile, COMPRESS_DETECT);

            print "<ul>";
            print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." smileys.conf...</div></li>"; ob_flush(); flush();
//            shell_exec("tar -cf ".$finalfile.".tar conf/smileys.conf");
            $files = array(DOKU_INC . "/conf/smileys.conf");
            if ($this->backup['pages'])
            {
                print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." ".$this->getLang('bt_pages')."...</div></li>"; ob_flush(); flush();
//                shell_exec("tar -rf ".$finalfile.".tar ".$conf['datadir']);
                $files = array_merge($files, directoryToArray($conf['datadir']));
            }
            if ($this->backup['revisions'])
            {
                print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." ".$this->getLang('bt_old_revisions_of_pages')."...</div></li>"; ob_flush(); flush();
//                shell_exec("tar -rf ".$finalfile.".tar ".$conf['olddir']);
                $files = array_merge($files, directoryToArray($conf['olddir']));
            }
            if ($this->backup['subscriptions'])
            {
                print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." ".$this->getLang('bt_meta_data_subscriptions')."...</div></li>"; ob_flush(); flush();
//                shell_exec("tar -rf ".$finalfile.".tar ".$conf['metadir']);
                $files = array_merge($files, directoryToArray($conf['metadir']));
            }
            if ($this->backup['media'])
            {
                print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." ".$this->getLang('bt_media_files')."...</div></li>"; ob_flush(); flush();
//                shell_exec("tar -rf ".$finalfile.".tar ".$conf['mediadir']);
                $files = array_merge($files, directoryToArray($conf['mediadir']));
            }
            if ($this->backup['config'])
            {
                print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." ".$this->getLang('bt_wiki_acl_user_config')."...</div></li>"; ob_flush(); flush();
//                shell_exec("tar -rf ".$finalfile.".tar conf/acl.auth.php");
//                shell_exec("tar -rf ".$finalfile.".tar conf/users.auth.php");
//                shell_exec("tar -rf ".$finalfile.".tar conf/local.php");
//                shell_exec("tar -rf ".$finalfile.".tar conf/local.protected.php");
                $files = array_merge($files, directoryToArray(DOKU_INC . "/conf"));
            }
            if ($this->backup['templates'])
            {
                print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." ".$this->getLang('bt_templates')."...</div></li>"; ob_flush(); flush();
//                shell_exec("tar -rf ".$finalfile.".tar lib/tpl");
                $files = array_merge($files, directoryToArray(DOKU_INC . "/lib/tpl"));
            }
            if ($this->backup['plugins'])
            {
                print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_archiving')." ".$this->getLang('bt_plugins')."...</div></li>"; ob_flush(); flush();
//                shell_exec("tar -rf ".$finalfile.".tar lib/plugins");
                $files = array_merge($files, directoryToArray(DOKU_INC . "/lib/plugins"));
            }

            print "<li class=\"level1\"><div class=\"li\">".$this->getLang('bt_compressing_archive')."...</div></li>"; ob_flush(); flush();
//            shell_exec("bzip2 -z -9 ".$finalfile.".tar");
//            print '<pre>$files:'; print_r($files); print '</pre>'; ob_flush(); flush();
            $success = $Archive->Add($files, "wiki_root", DOKU_INC);
            if ($success<=0) {
                print "<div class=\"error\">Error on creating archive: " . $Archive->TarErrorStr($success) . "</div>";
                print '<pre>$files:'; print_r($files); print '</pre>'; ob_flush(); flush();
                exit;
            }

            print "</ul>";
//            shell_exec("mv ".$finalfile.".tar.bz2 ".$conf['mediadir']."/".$finalfile.".tar.bz2");
            rename($finalfile, $conf['mediadir'] . "/" . $finalfilename);
            print $this->plugin_locale_xhtml('download');
            print $this->plugin_render('{{:'.$finalfilename.'}}');
            ob_flush(); flush();
        }
    }
}

// from http://snippets.dzone.com/posts/show/155 :
function directoryToArray($directory) {
    $array_items = array();
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && $file != "_dummy" && $file != "disabled") {
                $file = $directory . "/" . $file;
                if (is_dir($file)) {
                    $array_items = array_merge($array_items, directoryToArray($file));
                } else {
                    if(filesize($file) !== 0) $array_items[] = preg_replace("/\/\//si", "/", $file);
                }
            }
        }
        closedir($handle);
    }
    return $array_items;
}

You can also find it here: http://dokuwiki.1t2.us/10207
I hope this helps. Cheers,
Andreas
Avatar
andi (Administrator) #5
Member since May 2006 · 747 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Good work! Have you contacted the author of the original plugin to get this incorporated in a new version?
Read this if you don't get any useful answers.
awagner #6
Member since Nov 2007 · 14 posts
Group memberships: Members
Show profile · Link to this post
not yet. I was hoping that he would monitor this thread and I wouldn't have to write an email. But I will do so after the weekend...
altoyes #7
Member for 2 months · 9 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #4
hi awagner and all:

thankyou for this plugin.

i have had a go at using it, uploaded it into my plugins folder, to no effect....
so must be doing something wrong ...

could you give some details about what / how to use?
eg
1 what do i call it?
2 where do i upload it to?
3. do i put it inside a directory?
4. if so, what do i call the directory?
5. how do i make a backup?
6. how do i use the backup if i need to use it?
altoyes #8
Member for 2 months · 9 posts
Group memberships: Members
Show profile · Link to this post
hi again

i have just noticed the author of the plugin is terence grant.
is that you awagner?

if not you, i guess that means that this is a rewrite of another backup plugin?

if so .... hmmmm
This post was edited on 2008-07-07, 00:43 by altoyes.
awagner #9
Member since Nov 2007 · 14 posts
Group memberships: Members
Show profile · Link to this post
it's not my plugin. You can find the original version at http://tatewake.com/wiki/projects:backuptool_for_dokuwiki or http://wiki.splitbrain.org/plugin:backuptool
I had to make some adjustments to have it work at my installation where the original method to generate and compress the archive wouldn't work. So I've just posted file (admin.php) I have edited above, you have to get the rest of the files from the original package.
I've also just mailed the original author and asked him to consider including the changes in his next release.

HTH,
Andreas
altoyes #10
Member for 2 months · 9 posts
Group memberships: Members
Show profile · Link to this post
yep i found it - http://www.tatewake.com/wiki/projects:backuptool_for_dokuw…

everything made sense. so read the whole file - noted the disclaimer and discussion

i have replaced the admin.php and uploaded to plugin folder.

i tried the plugin out on a mirror of my main site
and i must not understand how to use it - for now i have a 500 error

which i do not know what to do with
so it is back to square one

i am sure this plugin works - i just do not know how
does anyone have any clues for me?

thankyou for your time

hi awagner, i have just seen your reply - thankyou
altoyes #11
Member for 2 months · 9 posts
Group memberships: Members
Show profile · Link to this post
i have just read   http://wiki.splitbrain.org/wiki:faq:error500

i have had my permissions changed to 777 - that might have something to do with it...

i am on a shared unix server.

what do others use for their write settings on shared unix server - 776?

this is getting off topic - my apologies - if i have any further queries about error 500, i will post elsewhere.
tatewake #12
Member since Nov 2007 · 4 posts
Group memberships: Members
Show profile · Link to this post
Hi all,

This is Terence, I'm the author of the original BackupTool plugin.

I've checked out Andreas Wagner's version of BackupTool which utilizes the "Maxg Tar" library.

Unfortunately, there is a major bug in Maxg Tar that can result in corrupted tar files if file names plus namespace paths are above roughly 75 characters. This is an easy number to approach with dokuwiki, especially considering things like old revisions (attic) files that include the page name, the namespace, and a timestamp in the file name.

So this means that for now, if you use the Maxg version, your backups will be missing files. This bug has been around since 2006, when I had tried the same thing Mr. Wagner did. This is a very frustrating bug in my opinion.

So for now I highly suggest you not use the Maxg version of BackupTool posted here until Maxg within DokuWiki is fixed.
If you absolutely must back up your wiki but have no permissions to shell_exec or simply do not have command line tar, my suggestion would be to use manual FTP backups. (But this is your choice, of course.)

However, I expect Mr. Wagner's version to become the new version of BackupTool once this fix is made in DokuWiki (which I'll make available through the original BackupTool site) since it is written much more elegantly than even my Maxg attempt.  :-)

Here is the official bug report if you're curious:
http://bugs.splitbrain.org/index.php?do=details&task_i…
awagner #13
Member since Nov 2007 · 14 posts
Group memberships: Members
Show profile · Link to this post
Hi,
thanks for seeing to this, Terence.

As noted in a PM to Terence, I have also encountered errors other than the too-long-filename one with TarLib.class. (Only it didn't seem to affect the contents/extractability of the archive.) I think it has to do with the tar format specs.

I am very interested in fixing this - either by fixing dokuwiki's tarlib.class (the original one doesn't seem to be maintained anymore) or by using another php library for this (like PEAR's Archive_Tar, e.g.) and I will continue digging and testing. But I would be glad if, if anyone reading this has some more suggestions or points to take into account, he/she would drop me a note (at Andreas dot Wagner at em dot uni-frankfurt dot de).

Thanks to all,
Andreas
awagner #14
Member since Nov 2007 · 14 posts
Group memberships: Members
Show profile · Link to this post
Subject: with PEAR
Got news:
I managed to get it working with one of the most popular PEAR packages: Archive_Tar

See the new version here, or the diff to the previous version here.

(I've also included a filter that prevents previous backup tarballs from going into the new one.)

Now perhaps it would be nice to be able to switch backends. Any thoughts?

Cheers,
Andreas
awagner #15
Member since Nov 2007 · 14 posts
Group memberships: Members
Show profile · Link to this post
Subject: new version
FYI, Terence has posted a new version of the plugin on the plugin's home page:

August 2, 2008

Major update!

Here's what's new:
I've made an effort for all run-time errors to be handled.
I've replaced shell_exec with just exec, since this is more appropriate for the command line version.
PEAR is now supported as an alternate to exec, thanks to Andreas Wagner for this.
The list of files to backup is much improved, again thanks to Andreas Wagner.
Backups will not archive existing backups, again thanks to Andreas Wagner.
I've added auto-detection of PEAR and/or exec availability, since not all users will have access to these.
You can choose between PEAR and exec if you have the option of both.
All files entries for the exec version are relative instead of absolute now for exec, thanks to Uwe Koloska for this.
Both backup methods generate the same file structure now as well.
Backup file names have changed slightly, files now start with “dw-backup-”.
Backup options selected are now saved as defaults for future sessions.
Compression options are chosen based on what's available, in the order of bzip2, gzip, and no compression for both PEAR and exec.
Backup files are created directly into the media directory, so no moving is necessary.

I haven't yet found the time to test it myself, but the changelog looks really promising.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please note the verification code from the picture into the text field next to it.
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 1.6.4, © 2003-7 by Yves Goergen
Current time: 2008-08-21, 21:03:08 (UTC +02:00)
WikiForumIRCBugsTranslate