mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
🎨 check-backup : improve code readability
move exit conditions on top to avoid if/else nightmare
This commit is contained in:
@@ -214,22 +214,39 @@ catch(Exception $e)
|
|||||||
$sZipArchiveFile = MakeArchiveFileName().'.tar.gz';
|
$sZipArchiveFile = MakeArchiveFileName().'.tar.gz';
|
||||||
echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFile\n";
|
echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFile\n";
|
||||||
|
|
||||||
if (file_exists($sZipArchiveFile))
|
if (!file_exists($sZipArchiveFile))
|
||||||
|
{
|
||||||
|
RaiseAlarm("Missing backup file '$sZipArchiveFile'");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aStat = stat($sZipArchiveFile);
|
||||||
|
if (!$aStat)
|
||||||
|
{
|
||||||
|
RaiseAlarm("Failed to stat backup file '$sZipArchiveFile'");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$iSize = (int)$aStat['size'];
|
||||||
|
$iMIN = utils::ReadParam('check_size_min', 0);
|
||||||
|
if ($iSize <= $iMIN)
|
||||||
|
{
|
||||||
|
RaiseAlarm("Backup file '$sZipArchiveFile' too small (Found: $iSize, while expecting $iMIN bytes)");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo "Found the archive\n";
|
||||||
|
$sOldArchiveFile = MakeArchiveFileName(time() - 86400).'.tar.gz'; // yesterday's archive
|
||||||
|
if (file_exists($sOldArchiveFile))
|
||||||
{
|
{
|
||||||
if ($aStat = stat($sZipArchiveFile))
|
|
||||||
{
|
|
||||||
$iSize = (int) $aStat['size'];
|
|
||||||
$iMIN = utils::ReadParam('check_size_min', 0);
|
|
||||||
if ($iSize > $iMIN)
|
|
||||||
{
|
|
||||||
echo "Found the archive\n";
|
|
||||||
$sOldArchiveFile = MakeArchiveFileName(time() - 86400).'.tar.gz'; // yesterday's archive
|
|
||||||
if (file_exists($sOldArchiveFile))
|
|
||||||
{
|
|
||||||
if ($aOldStat = stat($sOldArchiveFile))
|
if ($aOldStat = stat($sOldArchiveFile))
|
||||||
{
|
{
|
||||||
echo "Comparing its size with older file: $sOldArchiveFile\n";
|
echo "Comparing its size with older file: $sOldArchiveFile\n";
|
||||||
$iOldSize = (int) $aOldStat['size'];
|
$iOldSize = (int)$aOldStat['size'];
|
||||||
$fVariationPercent = 100 * ($iSize - $iOldSize) / $iOldSize;
|
$fVariationPercent = 100 * ($iSize - $iOldSize) / $iOldSize;
|
||||||
$sVariation = round($fVariationPercent, 2)." percent(s)";
|
$sVariation = round($fVariationPercent, 2)." percent(s)";
|
||||||
|
|
||||||
@@ -247,21 +264,4 @@ if (file_exists($sZipArchiveFile))
|
|||||||
echo "The archive grew by: $sVariation\n";
|
echo "The archive grew by: $sVariation\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RaiseAlarm("Backup file '$sZipArchiveFile' too small (Found: $iSize, while expecting $iMIN bytes)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RaiseAlarm("Failed to stat backup file '$sZipArchiveFile'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
RaiseAlarm("Missing backup file '$sZipArchiveFile'");
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user