MyBB Community Forums

Full Version: Database Backup System
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Something's well and truely screwed with it. Happens once a month, without fail.

See screenshot for the reason. Backup task settings: Weekly Backup backupdb 0 0 * * 1

Just copied them straight from the database 'cause I'm lazy, but you should know what they mean.
Can you printscreen the page with the the task settings??
I can indeed.
It must be timing out. Either turn the automatic task off or tell your host to increase their timeout limit.

This really isn't a MyBB bug because it's the hosts settings interfering and there are just some natural limits of code and the amount of data it can process and how it can gracefully handle problems.
I'm getting some funny results from function_task::fetch_next_run(). Under some circumstances it's possible it returns a next run date that is already past.

Based on this task:
Array
(
    [tid] => 4
    [title] => Weekly Backup
    [description] => Automatically backups your MyBB tables to your backups directory.
    [file] => backupdb
    [minute] => 0
    [hour] => 0
    [day] => *
    [month] => *
    [weekday] => 1
    [nextrun] => 1234134000
    [lastrun] => 0
    [enabled] => 1
    [logging] => 1
    [locked] => 0
)

I called fetch_next_run($task) for the current time (Tue, 03 Feb 2009 17:42:04 +0100).

The current_ and next_ variables inside the function look as follows:
Array
(
    [current_minute] => 42
    [current_hour] => 17
    [current_day] => 03
    [current_weekday] => 2
    [current_month] => 02
    [current_year] => 2009
    [next_minute] => 0
    [next_hour] => 0
    [next_day] => 9
    [next_weekday] => 1
    [next_month] => 02
    [next_year] => 2009
)

So at this time it would run the task next at Mon, 09 Feb 2009 00:00:00 +0100. No problem.

Suppose the task runs on 09 Feb 2009 00:30 i.e. half hour late because there was no visitor earlier, this is what happens:

Array
(
    [current_minute] => 30
    [current_hour] => 00
    [current_day] => 09
    [current_weekday] => 1
    [current_month] => 02
    [current_year] => 2009
    [next_minute] => 0
    [next_hour] => 0
    [next_day] => 9
    [next_weekday] => 1
    [next_month] => 02
    [next_year] => 2009
)

On Mon, 09 Feb 2009 00:30:00 +0100 it schedules the task to be run next on Mon, 09 Feb 2009 00:00:00 +0100 i.e. half an hour in the past?

A task timing out should not cause the task to be run every time, as the nextrun is the first thing that gets updated, before the task itself is even run, to prevent just this from happening.

Is this code taken from somewhere or written from scratch? Scheduling logic is really hard to get right. Hard to verify that it gives the correct results for all cases too. Do you have a testsuite for this kind of thing?
Or is it supposed to work this way, i.e. by saving the last run timestamp and only run it when fetch next run returns something newer than the already saved last run? So many possibilities...

But then I don't see the point of this code?

                // Update the nextrun time now, so if the task causes a fatal error, it doesn't get stuck first in the queue
                $nextrun = fetch_next_run($task);
                $db->update_query("tasks", array("nextrun" => $nextrun), "tid='{$task['tid']}'");

If the task causes a fatal error (or times out) the update doesn't change anything, it sets nextrun to the same value always so its run and run again.
How can it be my host when every other database backup/export system, including manual ones on MyBB and ones for the entire database on phpMyAdmin or cPanel, done either via FTP or HTTP, have no problem whatsoever?
Fyi backups from cpanel usually are not limited by the host in terms of memory limit and timeouts such as the ones usually subject on hosting accounts.
I can reproduce this on my localhost.

Steps to reproduce:
- Make a vanilla install of the MyBB
- Open the forum index page in one tab
- Open the admin cp in another tab
- Go to Tasks, edit Weekly Backup task
- Check your current time, for me it's Wednesday Feb 04 00:26
- Set the task to execute every week for your current week day (in my case Wednesday) 00:00
- Enable the task (confirm with yes) (disable and re-enable if it already was enabled to reset the task)
- Go to the 'Database Backups'
- Reload the forum index page in the other tab 10 times
- Reload the Database Backups tab
- Find 10 backups

This is on my localhost on an empty forum (dump is only 50kb or so) and PHP / Apache is configured to not time out for a long time. The View Task Log is also filled with 'The database backup task successfully ran.' messages.

What's a bit confusing is that the tasks seem to be using local time, whereas the backup lists them in GMT time (one hour early) but looking at the files in the filesystem they have correct local time timestamps.
(2009-02-03, 11:38 PM)frostschutz Wrote: [ -> ]What's a bit confusing is that the tasks seem to be using local time, whereas the backup lists them in GMT time (one hour early) but looking at the files in the filesystem they have correct local time timestamps.

Tasks time stamps are internal - therefore they run off of the system time. Backups however are downloaded by administrators and should therefore have a single, universal time offset. In this case GMT.

(2009-02-03, 05:16 PM)frostschutz Wrote: [ -> ]Do you have a testsuite for this kind of thing?

The MyBB 1.* codebase wasn't originally built with test suites at mind because it was a really small product back then and techniques were still emerging. MyBB 2.0 will aim to address unit testing capabilities
Should this be moved back to Bug Reports then?
Pages: 1 2 3