[re-opened] CMSimple_XH: Backup and Restore

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by cmb » Sun Jul 17, 2011 9:05 pm

Hello Holger, hello Gert,

my interest in a backup/restore solution currently increased again, because of Pagemanager_XH. I would feel much better, if restoring files from the CMSimple_XH backend would be possible ;)

Did someone already had a look at Jens' solution? Is it possible to integrate his code (license and effort)? If the former is false, but the latter is true, I could try to do that.
Holger wrote: The user/admin can configure all files/folders of his choice to download and restore as a zip.
Is it correct, that this backup solution will require PHP >= 5.2 or the PECL zip?

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by cmb » Mon Jul 18, 2011 10:12 am

Hello developers,

I took a look at CMSimpleSE's (BTW: some very nice additions) restore solution. It is very nice, but I would suggest an even simpler solution: on restore the current content/pagedata will be renamed to the current date/time instead of deleting them. No 'keep' needs to be implemented. More advanced operations could be accomplished by a plugin.

First I like to suggest a tiny change to /cmsimple/login.php, to asure that content and pagedata are synchronized. Line 122ff:

Code: Select all

else if($logout && $adm) {
    // cmb: added $backup_date to synchronize content.htm and pagedata.php
    $backup_date = date("Ymd_His");
    $fn = $backup_date.'_content.htm';
// ...
    if(file_exists($pth['folder']['content'].'pagedata.php')){
        $fn = $backup_date.'_pagedata.php';
 
The basically necessary changes to /cmsimple/adm.php. Line 123 (added restore link; slightly rearranged for better readability):

Code: Select all

        foreach($fs as $p) 
        if(preg_match("/\d{3}_content\.htm|\d{3}_pagedata\.php/", $p))
            $o .= '<li><a href="'.$sn.'?file='.$p.amp().'action=view">'
                .$p.'</a> ('.(round((filesize($pth['folder']['content'].'/'.$p))/102.4)/10).' KB)'
                .(preg_match("/\d{3}_content\.htm/", $p)
                    ? ' <a href="'.$sn.'?restore&action='.$p.'">restore</a>'
                    : '')
                .'</li>'."\n";
 
Line 52ff (added new 'operation'):

Code: Select all

if ($adm) {

    if ($restore)$f = 'restore'; // cmb
// ...
if ($f == 'restore') {
    cmb_restore();
    $f = 'settings'; // to avoid an additional info screen about success/failure of the restore
}
 
Then somewhere in adm.php the actual restore function has to be added:

Code: Select all

/*
 * Restores content.htm and pagedata.php.
 */
function cmb_restore() {
    global $pth, $action, $e, $o;
    $cdate = date("Ymd_His");
    $bdate = substr($action, 0, strlen($cdate));
    $dir = $pth['folder']['content'];
    // try to rename the 4 files
    // rollback on failure (should not fail again, but nonetheless checked)
    if (rename($dir.'content.htm', $dir.$cdate.'_content.htm')) {
    if (rename($dir.'pagedata.php', $dir.$cdate.'_pagedata.php')) {
        if (rename($dir.$bdate.'_content.htm', $dir.'content.htm')) {
        if (rename($dir.$bdate.'_pagedata.php', $dir.'pagedata.php')) {
            $o .= '<p>Successfully restored '.$bdate.'</p>';
        } else {
            $success = rename($dir.'content.htm', $dir.$bdate.'_content.htm');
            $success &= rename($dir.$cdate, '_pagedata.php', $dir.'pagedata.php');
            $success &= rename($dir.$cdate.'_content.htm', $dir.'content.htm');
            if ($success) {
            $e .= '<li>Restore failed (4)</li>';
            } else {
            $e .= '<li>OOPS! I\'ve totally mixed up everything!</li>';
            }
        }
        } else {
        $success = rename($dir.$cdate, '_pagedata.php', $dir.'pagedata.php');
        $success &= rename($dir.$cdate.'_content.htm', $dir.'content.htm');
        if ($success) {
            $e .= '<li>Restore failed (3)</li>';
        } else {
            $e .= '<li>OOPS! I\'ve totally mixed up everything!</li>';
        }
        }
    } else {
        $success = rename($dir.$cdate.'_content.htm', $dir.'content.htm');
        if ($success) {
        $e .= '<li>Restore failed (2)</li>';
        } else {
        $e .= '<li>OOPS! I\'ve totally mixed up everything!</li>';
        }
    }
    } else {
    $e .= '<li>Restore failed (1)</li>';
    }
}
 
I've made some tests; seems to work. For inclusion to the core, several adjustments might be necessary, e.g. localization of the output.

Any comments appreciated.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by Holger » Tue Jul 19, 2011 10:09 pm

cmb wrote:Is it correct, that this backup solution will require PHP >= 5.2 or the PECL zip?
No. It needs PHP 5.0.0. No special extension is required, just the default date and pcre stuff.

But as I said above, it's not thought for a replacement of a content-restore.
The core should provide a simple solution for that job - maybe like you've posted before.
cmb wrote:Any comments appreciated.
Can't you provide downloads of the files? Or maybe you can start your own branch at SF?
It's really hard to follow your speed and ideas ;)

LG
Holger

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by cmb » Tue Jul 19, 2011 10:29 pm

Hello Holger,
Holger wrote: No. It needs PHP 5.0.0. No special extension is required, just the default date and pcre stuff.
But as I said above, it's not thought for a replacement of a content-restore.
Okay, so that shouldn't be the standard solution for the core. Even if it is very sophisticated. :)
Holger wrote: It's really hard to follow your speed and ideas
It's not that easy for me too ;)
Holger wrote: Can't you provide downloads of the files? Or maybe you can start your own branch at SF?
I've got no experience with SF, or SVN/CVS etc. I'd rather like to have at look at this--but I'll need more time.

I've checked the code I've posted. And you're absolutely right: it's very expensive to follow it. So I'll make available a patch on my website ASAP. I'll post, when it is available.

[EDIT]
If just put together the changes mentioned above into bar-0.1.zip. Just download, unzip and put the modified adm.php and login.php into your /cmsimple directory. In the back-end under settings you'll find a restore link for all content.htm files. Clicking it will restore the content.htm and the according pagedata.php.

Thanks for your interest and feedback!

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by cmb » Sat Jul 23, 2011 11:58 am

Hello developers,

I've just came across an older thread in OD, which relates to this thread, and brought me to ts_backup. I've downloaded it, and took a short glimpse at the code. I found it uses an own ZIP-class, to make it possible to be used under PHP 4.3 without installed extensions.

And I've reread this thread. So I like to summarize:
Gert wrote: I think, what we need is a simple possibility in the backend to rename the current content.htm and pagedata.php to "date_time_content.htm" and "date_time_pagedata.php", and rename one of the Server Backups to content.htm and pagedata.php in the normal backend. Maybe it should be realized in the admin.php, as core solution.
+ 1
This is exactly what bar-0.1 does.
Holger wrote: The core should provide a simple solution for that job - maybe like you've posted before.
+ 1

But I like to suggest an addition to my current solution. IMO it would be better manageable by the end-user and more consistent with my already suggested handling of the restore. Instead of the message "Please save the Content-file and the Pagedata-file always together!" there should be only one link, to download content.htm and pagedata.php together. I had suggested this earlier, but I couldn't implement a solution, because AFAIK the PHP 4.3 core doesn't provide the possibility to create tarballs or zip files. But ts_backup showed me how to do it. So I'll try to contact it's author for permission to reuse his code for a possible addition to CMSimple_XH's core. IMO it's not necessary to store template.htm or stylesheet.css with the content and pagedata, as content and layout are seperate in a CMS anyway.

IMO those modifications for CMSimple_XH's core should be enough. More comprehensive backup and restore solutions are already given by ts_backup and Holger's upcoming backup&restore solution. And it's IMHO not reasonable to store the whole content folder at once. Consider the user having a gallery with 1000 images of 100KB each. So the each download will have a size of 100MB!

Any comments appreciated.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by Holger » Sat Jul 23, 2011 4:37 pm

@cmb:
cmb wrote:o I'll try to contact it's author for permission to reuse his code for a possible addition to CMSimple_XH's core.
You may have a look here:
http://cmsimple.holgerirmler.de/?Plugins:Backup

It's a older plugin I've created some time ago. It has no restore-function like my new one.
It's using the same zip-class from phpMyAdmin like ts_Backup, but the admin has the choice to configure additional files to backup in the configuration.
Feel free to use some code for a content/pagedata - backup.

KR
Holger

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by cmb » Sat Jul 23, 2011 4:46 pm

Hello Holger,

thanks for your hint and the permission to reuse the code. I'll have a look at it.

In the meantime I've already got permission from the author of ts_backup to reuse his code too.

So it should be pretty easy to implement the content/pagedata backup :D

Christoph

PS: Thanks again for giving this link. I only had a glimpse at the documention and ... oops, I hadn't considered multi-language installations! I wondered, how this is solved by CMSimple_XH, and found that it already cares for it. The back-ups that are displayed in the backend belong to the active language, and when logging out, the content and pagedata of the active language are backed up. So it is the users responsibility to logout separately for each language he has edited. Perhaps this should be documented by somebody ;) I've checked my 'bar' draft and found, that it handles this consistently with the rest of CMSimple_XH by using $pth['folder']['content'] instead of a hard coded path to the content :D
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: [re-opened] CMSimple_XH: Backup and Restore

Post by cmb » Sat Jul 23, 2011 9:55 pm

Hello developers,

thanks to Till's and Holger's friendly permission to reuse the code of their backup solutions, I was able to provide a basic backup solution in a rather short time. Thanks to both of you! :)

You can download bar-0.2.zip, if you want to test it, or look at the modifications I've made. Just copy the unzipped files to the /cmsimple/ folder of a test installation.

A short summary:

In the lower part of settings are the lists of content.htm and pagedata.php files (standard CMSimple_XH behaviour). I've changed the download link for the current content and pagedata to download both files in a zip archive. I've added a restore link to all content.htm files. After confirmation the selected pair of content and pagedata are restored as the current ones, and the current ones are stored as new backup. On logging out content and pagedata are stored as usual, but it's guaranteed now, that they have the same date/time prefix. Everything works for the active language as usual.

What's missing:
- i18n
- removal of $tx['settings']['backupexplain3']
- perhaps changing the output of the files as <ul> to <table>, so the backup and restore links could use rowspan=2 with according align

IMO these modifications to the core are a useful extension, and assure more consistency regarding content and pagedata.

Any comments appreciated.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply