Permalink
Browse files

Improved next block number. Added block conflict detection.

  • Loading branch information...
cubiclesoft committed Jun 27, 2018
1 parent ab10c21 commit 6e0572e48d1575a3c34cff8698a786ead3776e34
Showing with 44 additions and 9 deletions.
  1. +1 −1 backup.php
  2. +6 −0 restore.php
  3. +4 −2 support/cb_cloud_storage_server.php
  4. +10 −2 support/cb_functions.php
  5. +4 −2 support/cb_local.php
  6. +4 −2 support/cb_opendrive.php
  7. +15 −0 verify.php
View
@@ -565,7 +565,7 @@
// Finalize the service side of things.
$lastbackupid++;
$result = $service->FinishBackup($lastbackupid);
$result = $service->FinishBackup($lastbackupid, $servicehelper->GetNextBlock());
if (!$result["success"]) CB_DisplayError("Unable to finish the " . $servicename . " backup.", $result);
$incrementals = $result["incrementals"];
View
@@ -98,12 +98,18 @@ function CleanupCache()
file_put_contents($filename, serialize($blocklist2));
}
unset($blocklist[0]);
unset($blocklist[1]);
foreach ($blocklist2 as $key => $val)
{
$blocklist[$key] = array("inc" => $x, "parts" => $val);
}
}
if (!isset($blocklist[0])) CB_DisplayError("Missing the files database for the " . ($backupnum ? "incremental " : "base ") . $backupnum . ". Backup needs repair.");
if (!isset($blocklist[1])) CB_DisplayError("Missing the deleted blocks list for the " . ($backupnum ? "incremental " : "base ") . $backupnum . ". Backup needs repair.");
// Retrieve the files database.
$filename = $rootpath . "/cache/restore_" . $backupnum . "_files.db";
@unlink($filename . "-journal");
@@ -112,6 +112,7 @@ public function GetBackupInfo()
// Initialize summary.
if (!isset($this->summary["incrementaltimes"])) $this->summary["incrementaltimes"] = array();
if (!isset($this->summary["lastbackupid"])) $this->summary["lastbackupid"] = 0;
if (!isset($this->summary["nextblock"])) $this->summary["nextblock"] = -1;
if (!isset($this->summary["mergeops"])) $this->summary["mergeops"] = array();
// Process remaining merge operations to restore backup stability.
@@ -163,7 +164,7 @@ public function UploadBlock($blocknum, $part, $data)
public function SaveSummary($summary)
{
$data = json_encode($summary);
$data = json_encode($summary, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
// Upload the summary.
// Cover over any Cloud Storage Server upload issues by retrying with exponential fallback (up to 30 minutes).
@@ -179,13 +180,14 @@ public function SaveSummary($summary)
return $result;
}
public function FinishBackup($backupid)
public function FinishBackup($backupid, $nextblock)
{
$summary = $this->summary;
$incrementals = $this->incrementals;
$summary["incrementaltimes"][] = time();
$summary["lastbackupid"] = $backupid;
$summary["nextblock"] = $nextblock;
// Move the TEMP folder to a new incremental.
$result = $this->css->RenameObject($this->remotetempfolderid, (string)count($incrementals));
View
@@ -504,6 +504,7 @@ public function StartService()
$result["servicename"] = $servicename;
$result["service"] = $this->service;
$this->nextblock = $result["summary"]["nextblock"];
return $result;
}
@@ -513,11 +514,13 @@ public function SetDB($db)
$this->db = $db;
// Retrieve the next block number.
$this->nextblock = (int)$this->db->GetOne("SELECT", array(
$nextblock = (int)$this->db->GetOne("SELECT", array(
"MAX(blocknum)",
"FROM" => "?",
), "files") + 1;
if ($this->nextblock < 10) $this->nextblock = 10;
if ($nextblock < 10) $nextblock = 10;
if ($this->nextblock < $nextblock) $this->nextblock = $nextblock;
// Initialize the shared block.
$this->sharedblockdata = "";
@@ -527,6 +530,11 @@ public function SetDB($db)
$this->bytessent = 0;
}
public function GetNextBlock()
{
return $this->nextblock;
}
public function DisplayStats($prefix)
{
$numfiles = (int)$this->db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum > 0 AND sharedblock = 0"), "files");
View
@@ -94,6 +94,7 @@ public function GetBackupInfo()
// Initialize summary.
if (!isset($this->summary["incrementaltimes"])) $this->summary["incrementaltimes"] = array();
if (!isset($this->summary["lastbackupid"])) $this->summary["lastbackupid"] = 0;
if (!isset($this->summary["nextblock"])) $this->summary["nextblock"] = -1;
if (!isset($this->summary["mergeops"])) $this->summary["mergeops"] = array();
// Process remaining merge operations to restore backup stability.
@@ -140,19 +141,20 @@ public function SaveSummary($summary)
{
$filename = $this->remotebasefolder . "/summary.json";
$result = @file_put_contents($filename, json_encode($summary));
$result = @file_put_contents($filename, json_encode($summary, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
if ($result === false) return array("success" => false, "error" => self::LTranslate("Unable to write data to '%s'.", $filename), "errorcode" => "invalid_filename");
return array("success" => true);
}
public function FinishBackup($backupid)
public function FinishBackup($backupid, $nextblock)
{
$summary = $this->summary;
$incrementals = $this->incrementals;
$summary["incrementaltimes"][] = time();
$summary["lastbackupid"] = $backupid;
$summary["nextblock"] = $nextblock;
// Move the TEMP folder to a new incremental.
$result = @rename($this->remotetempfolder, $this->remotebasefolder . "/" . (string)count($incrementals));
View
@@ -129,6 +129,7 @@ public function GetBackupInfo()
// Initialize summary.
if (!isset($this->summary["incrementaltimes"])) $this->summary["incrementaltimes"] = array();
if (!isset($this->summary["lastbackupid"])) $this->summary["lastbackupid"] = 0;
if (!isset($this->summary["nextblock"])) $this->summary["nextblock"] = -1;
if (!isset($this->summary["mergeops"])) $this->summary["mergeops"] = array();
// Process remaining merge operations to restore backup stability.
@@ -180,7 +181,7 @@ public function UploadBlock($blocknum, $part, $data)
public function SaveSummary($summary)
{
$data = json_encode($summary);
$data = json_encode($summary, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
// Upload the summary.
// Cover over any OpenDrive upload issues by retrying with exponential fallback (up to 30 minutes).
@@ -196,13 +197,14 @@ public function SaveSummary($summary)
return $result;
}
public function FinishBackup($backupid)
public function FinishBackup($backupid, $nextblock)
{
$summary = $this->summary;
$incrementals = $this->incrementals;
$summary["incrementaltimes"][] = time();
$summary["lastbackupid"] = $backupid;
$summary["nextblock"] = $nextblock;
// Move the TEMP folder to a new incremental.
$result = $this->opendrive->RenameFolder($this->remotetempfolderid, (string)count($incrementals));
View
@@ -90,13 +90,28 @@ function CleanupCache()
$blocklist2 = $result["blocklist"];
unset($blocklist[0]);
unset($blocklist[1]);
$conflicts = 0;
foreach ($blocklist2 as $key => $val)
{
if (isset($blocklist[$key]))
{
CB_DisplayError("[Error] Backup " . $x . " already has block number " . $key . ".", false, false);
$conflicts++;
}
$blocklist[$key] = array("inc" => $x, "parts" => $val);
@unlink($rootpath . "/cache/verify_" . $key . ".dat");
}
if ($conflicts) CB_DisplayError("Backup " . $x . " has " . ($conflicts == 1 ? "1 block" : $conflicts . " blocks") . " conflicting. Backup needs repair.");
if (!isset($blocklist[0])) CB_DisplayError("Missing the files database for the " . ($x ? "incremental " : "base ") . $x . ". Backup needs repair.");
if (!isset($blocklist[1])) CB_DisplayError("Missing the deleted blocks list for the " . ($x ? "incremental " : "base ") . $x . ". Backup needs repair.");
if (isset($backups[$x]))
{
echo "Testing backup " . $x . "...\n";

0 comments on commit 6e0572e

Please sign in to comment.