manually restore backup to the same domain

lodria
Master Bludit
Posts: 176
Joined: Wed Jan 29, 2020 8:32 pm
Has thanked: 38 times
Been thanked: 20 times

Hi!

A friend of mine's page doesn't open the existing pages for some reason. The content is on the storage. The content is copied. Bludit runs on it, but it doesn't open the individual posts. What should I do so that a new Bludit install opens the pages txt files? Or can I just manually open the txt files one by one? Do I create the address and copy the content of the txt files and copy the images for uploads? Does anyone have an idea, because I would have to copy a lot of articles manually.

thanks
User avatar
indocreativemedia
Jr. Bludit
Posts: 9
Joined: Sun Sep 24, 2023 5:09 am
Been thanked: 2 times

Hi,

Bludit doesn't autodiscover files into pages. Bludit stores page contents into /bl-content/databases/pages.php

If your page-file isn't found inside that pages.php, then, for a safe way, you need to re-entry that page via add new content. You can set a custom date via Options > Advanced.

Hope this helps.
lodria
Master Bludit
Posts: 176
Joined: Wed Jan 29, 2020 8:32 pm
Has thanked: 38 times
Been thanked: 20 times

Thanks. I think this file might be corrupted: pages.php. All the content is there, but pages.php is practically empty.
arfa
Master Bludit
Posts: 156
Joined: Tue Jul 04, 2017 4:31 am
Location: New Zealand
Has thanked: 13 times
Been thanked: 26 times

Hi,
I am curious to know if you found any cause for the page.php corruption – or any sense of how the general 'mess' happened; it might be useful in future context ... as in "be sure not to... " or some such.

I haven't given it a great deal of thought but figure it would be easy enough to write a script to rebuild page.php – dates would need later, manual adjustment. And I am not sure how adaptable is:
md5file (used in pages.class.php - md5 hash)
uuid (more widely used)
Someone (more clever than me :)) may have suggestions as to how to manage these.
All the other fields can be easily enough added. Just a thought.

good luck - Kusalo
lodria
Master Bludit
Posts: 176
Joined: Wed Jan 29, 2020 8:32 pm
Has thanked: 38 times
Been thanked: 20 times

I created this little blog based on Bludit for kids. With free storage and a free subdomain. Although it's a good service provider, they don't make backups for free services. So unfortunately I can't restore from the backup. I didn't suspect any tampering. The storage was full, which gave me cause for suspicion. But what usually happens in these cases is that you can't upload an image or something similar, but I ruled that out again. The CMS system seemed to have restarted and all the articles that were there locally disappeared, but this was because pages.php was empty. The CMS itself continued to work in every way. There was also no php problem. Because it wasn't tampered with either. So for now I'm telling the guys that it would be better if they re-entered their writings and although it might take a while, it's still better than nothing being left. So some solution would be nice that would simplify this, but I don't think there will be one because this is not a general error.
arfa
Master Bludit
Posts: 156
Joined: Tue Jul 04, 2017 4:31 am
Location: New Zealand
Has thanked: 13 times
Been thanked: 26 times

hi Lodria,

A kids project – I am happy to support that.

Assuming that your page index.txt files are in order you can use this script to rebuild pages.php

Code: Select all

<?php
$pagesDir = __DIR__ . '/bl-content/pages';
$outputFile = __DIR__ . '/bl-content/databases/pages.php';
$pages = [];

foreach (scandir($pagesDir) as $slug) {
    if ($slug === '.' || $slug === '..' || stripos($slug, 'autosave-') !== false ) continue;
        $pagePath = $pagesDir . '/' . $slug;
    if (!is_dir($pagePath)) continue;

    $title = ucwords(str_replace('-', ' ', $slug));
    $indexFile = $pagePath . '/index.txt';
        $md5 = file_exists($indexFile) ? md5_file($indexFile) : '';
        $created = date('Y-m-d H:i:s', filectime($pagePath));
    // filemtime() for last modified ?
    $modified = file_exists($indexFile) ? date('Y-m-d H:i:s', filemtime($indexFile)) : '';

    $type = ($slug === 'menu') ? 'static' : 'published';
    $pages[$slug] = [
        'title' => $title,
        'description' => '',
        'username' => 'admin',
        'tags' => [],
        'type' => $type,
        'date' => $created,
        'dateModified' => $modified,
        'position' => 1,
        'coverImage' => '',
        'category' => '',
        'md5file' => $md5,
        'uuid' => md5(uniqid($slug, true)),
        'allowComments' => true,
        'template' => '',
        'noindex' => false,
        'nofollow' => false,
        'noarchive' => false,
        'custom' => [false]
    ];
}
$jsonData = json_encode($pages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$output = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>\n" . $jsonData;
file_put_contents($outputFile, $output);
put this code in a file (say newPages.php) in the top dir and it should work fine. I have tested it on an offline test site I have and it works fine. You could add another scandir loop using dateModified to better set the position; currently all '1'.

I hope this solves the issue.
go well - kusalo
lodria
Master Bludit
Posts: 176
Joined: Wed Jan 29, 2020 8:32 pm
Has thanked: 38 times
Been thanked: 20 times

Well, thank you very much! I hope it works out. I'll report back on the results and of course I'll come back to you.
lodria
Master Bludit
Posts: 176
Joined: Wed Jan 29, 2020 8:32 pm
Has thanked: 38 times
Been thanked: 20 times

I need a little more help. Could you please be more specific about what to do, because I haven't been able to solve it based on what you wrote so far.

Thanks
arfa
Master Bludit
Posts: 156
Joined: Tue Jul 04, 2017 4:31 am
Location: New Zealand
Has thanked: 13 times
Been thanked: 26 times

It is always a guess to know how much to assume regarding anyone's code experience.

I presume you have FTP access?
Create a local file - say 'newPages.php' and add the code to it. Perhaps create a .txt file and later rename it?
upload that file to yourdirectory. You mentioned a subdomain? Upload to:
https://yourSub.yourMain/newPages.php
and then run that as a link in your browser.

You might want to rename the old pages.php – even if it is rubbish it is something.
The code should write a new file: '/bl-content/databases/pages.php'

now... an update on the code...
it will write the file and should see the site working but – ain't there always one? – I found that I could not login to admin with the new pages.php. And that's a big BUTT. This must surely have something to do with md5 and uuid – ie. security.

Do test the code and see if the site runs.

My next thought is another script built using the index.txt files directly, perhaps with a time delay as each pages.php array element is built so that the two values are not suspiciously (security) coincident.

I hope that this makes enough sense. Don't hesitate to question further. You are a contributor and, with such a small bludit-niche, giving time here is a pleasure.

PS. I am slowly getting into the bludit engine but my knowledge is still limited. I enjoy poking around and learning along the way.
lodria
Master Bludit
Posts: 176
Joined: Wed Jan 29, 2020 8:32 pm
Has thanked: 38 times
Been thanked: 20 times

I managed to solve it! Thank you very much! ;)
Post Reply