Automatic backups not properly scheduling

strikedo - September 21, 2008 - 15:04
Project:Backup Client-Server
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I have set daily backups using this module.

Expectation: if my first backup is on 9/15 at 1:00am, I expect the next daily backup to be on 9/16 at 1:00am, then 9/17 at 1:00am etc. In other words, every day at 1:00am.

Reality: backups are being saved as follows: 9/15 1:00am, 9/16 2:00am, 9/17 3:00am, 9/18 4:00am

In other words, each daily backup is shifting forward by one hour.

I assume this is because I have cron set up to run on an hourly basis. When cron is triggered it is comparing the current time to the time of the last backup and because the last backup is *exactly* 24 hours old, it does not make a new backup. One hour later at the next cron, the last backup is 25 hours old (25>24) therefore a new backup is made.

#1

phacts - January 29, 2009 - 03:34

I saw this and looked at the code, there are two functions that control when its time for a backup or time for a mysqldump, _backup_client_time_for_backup() and _backup_client_time_for_mysqldump(). The code checks > instead of >=, so I changed the following lines:

Line 379 is:

  if ($span > variable_get('backup_client_backup_day_frequency', '1') * 86400) {

Line 379 becomes:

  if ($span >= variable_get('backup_client_backup_day_frequency', '1') * 86400) {

Then we make the change in _backup_client_time_for_mysqldump() just below.

Line 385 is:

  if ($span > variable_get('backup_client_dump_day_frequency', '1') * 86400) {

Line 385 becomes:

  if ($span >= variable_get('backup_client_dump_day_frequency', '1') * 86400) {

Now, I haven't quite tested this out.. and I don't really see it being a problem. The only possible problem would be with the "every second" setting for backups, which isn't all that useful anyway. In that case... it still wouldn't be a problem, because it takes more than a second for each backup.

Should I turn this into a patch?

#2

phacts - February 9, 2009 - 16:15

My above solution to this problem does NOT work - and now I know why. The $span variable is referring to the difference between the current time and the last time the backup was run. Since the backup takes progressively longer to run each day as your site grows (even if its only a second, its still longer), when you say $span >= your frequency, you end up being a few seconds off.

A simplified example - span is calculated here:
$span = time() - variable_get('backup_client_time_of_last_backup', 0);
if time() returns 1000, and the time of the last backup was . . . 800 seconds ago, our span would be 200. Now, lets pretend we want to backup our site every 200 seconds. In this case, we would say if (200 >= 200) and our backup would happen. However, in real life the time that it takes to actually DO the backup will add a few seconds to the time of the last backup.

So, if it takes 2 seconds to do the backup, we will calculate $span by doing 1000 - 802, which gives us 198, so if (198 >= 200) returns false, and our backup gets pushed back an hour each day.

My new solution is to use a different variable - on line 378, change $span = time() - variable_get('backup_client_time_of_last_backup', 0); to be $span = time() - variable_get('backup_client_time_of_backup_start', 0);

I will test this in my case, and report back here with details on whether or not it works.

 
 

Drupal is a registered trademark of Dries Buytaert.