function takeScheduledBackupSnapshot(backupJob $job)
 {
     global $config;
     $scheduledBackup = $job->getScheduledBackup();
     // First fetch info to know what we're backing up
     // Validate the parameters of this backup, before we proceed.
     $params = $scheduledBackup->getParameters();
     $this->validateParams($params);
     // Get info on the backup
     $sbInfo = $scheduledBackup->getInfo();
     // Get the host of the backup
     $sbHost = $scheduledBackup->getHost();
     $hostInfo = $sbHost->getInfo();
     // Setup to write to host log
     if (!is_object($this->infolog)) {
         $infolog = new logStream($config['LOGS']['logdir'] . '/hosts/' . $hostInfo['hostname'] . '.log', $this->infologVerbose, $config['LOGS']['level']);
         $this->setInfoLogStream($infolog);
     }
     $backupTaker = new genericBackupTaker();
     $backupTaker->setInfoLogStream($this->infolog);
     $backupTaker->setTicketsToReleaseOnStart($this->ticketsToReleaseOnStart);
     $sbGroups = $scheduledBackup->getSnapshotGroupsNewestToOldest();
     // If there is one group and no backup yet, take a full backup for group 0
     if (sizeOf($sbGroups) == 1 && $sbGroups[0]->getSeed() === false) {
         $backupTaker->takeFullBackupSnapshot($job, $sbGroups[0]);
     } else {
         // Otherwise, create the next group and take the next backup there...
         $newGroup = $this->groupFactory->getNextSnapshotGroup($sbGroups[0]);
         $backupTaker->takeFullBackupSnapshot($job, $newGroup);
     }
     return true;
 }
 function takeScheduledBackupSnapshot(backupJob $job)
 {
     global $config;
     $scheduledBackup = $job->getScheduledBackup();
     // First fetch info to know what we're backing up
     // Validate the parameters of this backup, before we proceed.
     $params = $scheduledBackup->getParameters();
     $this->validateParams($params);
     // Get info on the backup
     $sbInfo = $scheduledBackup->getInfo();
     // Get the host of the backup
     $sbHost = $scheduledBackup->getHost();
     $hostInfo = $sbHost->getInfo();
     // Setup to write to host log
     if (!is_object($this->infolog)) {
         $infolog = new logStream($config['LOGS']['logdir'] . '/hosts/' . $hostInfo['hostname'] . '.log', $this->infologVerbose, $config['LOGS']['level']);
         $this->setInfoLogStream($infolog);
     }
     $backupTaker = new genericBackupTaker();
     $backupTaker->setInfoLogStream($this->infolog);
     $backupTaker->setTicketsToReleaseOnStart($this->ticketsToReleaseOnStart);
     $sbGroups = $scheduledBackup->getSnapshotGroupsNewestToOldest();
     // There should only be one group...
     if (sizeOf($sbGroups) > 1) {
         throw new Exception('continuousIncrementalBackupTaker->takeScheduledBackupSnapshot: ' . "Error: Found more than one snapshot group for a backup using continuous incremental strategy.");
     }
     // Find if there is a seed..
     $seedSnap = $sbGroups[0]->getSeed();
     // If this group has a seed snapshot, then take incremental...
     if ($seedSnap) {
         $backupTaker->takeIncrementalBackupSnapshot($job, $sbGroups[0], $sbGroups[0]->getMostRecentCompletedBackupSnapshot());
         // Otherwise take a FULL backup
     } else {
         $backupTaker->takeFullBackupSnapshot($job, $sbGroups[0]);
     }
     return true;
 }
 function takeScheduledBackupSnapshot(backupJob $job)
 {
     global $config;
     $scheduledBackup = $job->getScheduledBackup();
     // First fetch info to know what we're backing up
     // Get info on the backup
     $sbInfo = $scheduledBackup->getInfo();
     // Get the host of the backup
     $sbHost = $scheduledBackup->getHost();
     $hostInfo = $sbHost->getInfo();
     // Setup to write to host log
     if (!is_object($this->infolog)) {
         $infolog = new logStream($config['LOGS']['logdir'] . '/hosts/' . $hostInfo['hostname'] . '.log', $this->infologVerbose, $config['LOGS']['level']);
         $this->setInfoLogStream($infolog);
     }
     // Get the params for the scheduledBackup and validate them...
     $sbParams = $scheduledBackup->getParameters();
     $this->validateParams($sbParams);
     // create a generic backup taker to use for snapshot taking.
     $backupTaker = new genericBackupTaker();
     $backupTaker->setInfoLogStream($this->infolog);
     $backupTaker->setTicketsToReleaseOnStart($this->ticketsToReleaseOnStart);
     // Get the snpshot groups for this scheduled backup
     $snapshotGroups = $scheduledBackup->getSnapshotGroupsNewestToOldest();
     //
     // Handle the case where we dont have any snapshots yet at all.
     //
     $this->infolog->write("Using " . $sbParams['rotate_method'] . " as the rotation method...", XBM_LOG_INFO);
     // if we have only one group...
     if (sizeOf($snapshotGroups) == 1) {
         // and we dont even have a seed yet...
         if ($snapshotGroups[0]->getSeed() === false) {
             // take a seed snapshot and then return
             $this->infolog->write("No snapshots found for this scheduled backup at all - taking an initial full backup.", XBM_LOG_INFO);
             $backupTaker->takeFullBackupSnapshot($job, $snapshotGroups[0]);
             return true;
         }
     }
     // Now handle things based on rotate_method...
     switch ($sbParams['rotate_method']) {
         case 'DAY_OF_WEEK':
             // Figure out what day of the week it is.
             $launchDayOfWeek = date('w', $this->launchTime);
             // is it the day of the week we should be rotating?
             $rotateDays = explode(',', $sbParams['rotate_day_of_week']);
             // This is kind of stupid but it was quicker than trying to coerce date functions to play nice.
             $dayList = array(0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');
             $msg = "Set to rotate on: ";
             foreach ($rotateDays as $dayOfWeek) {
                 $msg .= $dayList[$dayOfWeek] . "  ";
             }
             $this->infolog->write($msg, XBM_LOG_INFO);
             $this->infolog->write("This backup was launched on a " . $dayList[$launchDayOfWeek], XBM_LOG_INFO);
             // if yes..
             if (in_array($launchDayOfWeek, $rotateDays)) {
                 $this->infolog->write("Based on the launch time of this backup, a rotate should be attempted.. checking if we already rotated today...", XBM_LOG_INFO);
                 // get the seed of the newest group and find out what day it was taken
                 $newestSeed = $snapshotGroups[0]->getSeed();
                 $seedInfo = $newestSeed->getInfo();
                 $seedDate = date('Ymd', strtotime($seedInfo['creation_time']));
                 $launchDate = date('Ymd', $this->launchTime);
                 // was the seed taken today ?
                 // if no, create next group and take seed
                 if ($launchDate != $seedDate) {
                     $this->infolog->write("No FULL backup found today - rotating to the next snapshot group and taking a full backup for it.", XBM_LOG_INFO);
                     $newGroup = $this->groupFactory->getNextSnapshotGroup($snapshotGroups[0]);
                     $backupTaker->takeFullBackupSnapshot($job, $newGroup);
                     return true;
                 }
                 $this->infolog->write("Found that we already took a FULL backup today, no rotation needed - proceeding to take an incremental.", XBM_LOG_INFO);
             } else {
                 $this->infolog->write("Based on the launch time of this backup, no rotation should occur today - proceeding to take an incremental.", XBM_LOG_INFO);
             }
             // we get here if either
             // a) its not the day of week to take a seed
             // b) it is the day of week to take a seed, but we already took one
             // check to see if we can go ahead and take an incremental for the current group in that case..
             // how many snapshots do we have in the current group?
             $snapshots = $snapshotGroups[0]->getAllSnapshotsNewestToOldest();
             // is it >= max?
             // if yes - stop and if we treat this critical throw an exception/failure
             if (sizeOf($snapshots) >= $sbParams['max_snapshots_per_group']) {
                 if (!isset($sbParams['backup_skip_fatal']) || $sbParams['backup_skip_fatal'] == 1) {
                     throw new Exception('rotatingBackupTaker->takeScheduledBackupSnapshot: ' . "Error: Refusing to take another backup, as max_snapshots_per_group would be exceeded.");
                 }
                 $this->infolog->write("Refusing to take another backup, as max_snapshots_per_group would be exceeded. Not treating as fatal due to backup_skip_fatal being disabled.", XBM_LOG_INFO);
                 return true;
             }
             // if no, go ahead and take incremental
             $backupTaker->takeIncrementalBackupSnapshot($job, $snapshotGroups[0], $snapshotGroups[0]->getMostRecentCompletedBackupSnapshot());
             break;
         case 'AFTER_SNAPSHOT_COUNT':
             // get the number of snapshots in the newest group
             $snaps = $snapshotGroups[0]->getAllSnapshotsNewestToOldest();
             $this->infolog->write("Detected " . sizeOf($snaps) . " snapshots in current group and we are configured to rotate after number " . $sbParams['rotate_snapshot_no'] . ".", XBM_LOG_INFO);
             // is it >= maximum?
             if (sizeOf($snaps) >= $sbParams['rotate_snapshot_no']) {
                 $this->infolog->write("Rotating to the next group and taking a full backup for it.", XBM_LOG_INFO);
                 // if yes, create new group and take seed
                 $newGroup = $this->groupFactory->getNextSnapshotGroup($snapshotGroups[0]);
                 $backupTaker->takeFullBackupSnapshot($job, $newGroup);
                 return true;
             } else {
                 // if no, create new incremental in current group based on the most recent complete snap for the group
                 $this->infolog->write("No group rotation needed - proceeding with incremental backup.", XBM_LOG_INFO);
                 $backupTaker->takeIncrementalBackupSnapshot($job, $snapshotGroups[0], $snapshotGroups[0]->getMostRecentCompletedBackupSnapshot());
                 return true;
             }
             break;
         default:
             throw new Exception('rotatingBackupTaker->takeScheduledBackupSnapshot: ' . "Error: Could not find a handler for this rotate_method. This should never happen.");
     }
     return true;
 }