function getHost() { $info = $this->getInfo(); $hostGetter = new hostGetter(); $host = $hostGetter->getById($info['host_id']); return $host; }
function handleStatusAction() { $backupJobGetter = new backupJobGetter(); $backupJobGetter->setLogStream($this->log); $scheduledBackupGetter = new scheduledBackupGetter(); $scheduledBackupGetter->setLogStream($this->log); $hostGetter = new hostGetter(); $hostGetter->setLogStream($this->log); $runningJobs = $backupJobGetter->getRunning(); $backupRows = array(); foreach ($runningJobs as $job) { $info = $job->getInfo(); $scheduledBackup = $job->getScheduledBackup(); $host = $scheduledBackup->getHost(); $hostInfo = $host->getInfo(); $sbInfo = $scheduledBackup->getInfo(); $backupRows[] = array('Job ID' => $info['backup_job_id'], 'Host' => $hostInfo['hostname'], 'Backup Name' => $sbInfo['name'], 'Start Time' => $info['start_time'], 'Status' => $info['status'], 'PID' => $info['pid']); } if (sizeOf($backupRows) > 0) { $textTable = new ArrayToTextTable($backupRows); $textTable->showHeaders(true); $tableOutput = $textTable->render(true); print "Currently Running Backups:\n\n" . $tableOutput . "\n\n"; } else { print "There are no backups currently running.\n\n"; } }
function buildCron() { global $config; global $XBM_AUTO_INSTALLDIR; // Start with an empty string... $cron = '# This crontab is automatically managed and generated by ' . XBM_RELEASE_VERSION . "\n"; $cron .= "# You should NEVER edit this crontab directly, but rather reconfigure and use xbm-flush.php\n"; // Get All Hosts $hostGetter = new hostGetter(); $hosts = $hostGetter->getAll(); // Cycle through each host... foreach ($hosts as $host) { // Get host info .. $hostInfo = $host->getInfo(); if ($hostInfo['active'] == 'Y') { $cron .= "\n# Host - " . $hostInfo['hostname'] . "\n"; } else { continue; } // Get scheduled backups for host... $scheduledBackups = $host->getScheduledBackups(); // Cycle through each scheduled backup .. foreach ($scheduledBackups as $scheduledBackup) { // Get info for the scheduled backup .. $scheduledBackupInfo = $scheduledBackup->getInfo(); $sbParams = $scheduledBackup->getParameters(); $host = $scheduledBackup->getHost(); $hostInfo = $host->getInfo(); if ($scheduledBackupInfo['active'] == 'Y') { $cron .= "\n# Backup: " . $scheduledBackupInfo['name'] . " -- Strategy: " . $scheduledBackupInfo['strategy_code'] . "\n"; switch ($scheduledBackupInfo['strategy_code']) { case 'FULLONLY': $cron .= "# Params Used: max_snapshots: " . $sbParams['max_snapshots'] . "\n"; break; case 'CONTINC': $cron .= "# Params Used: max_snapshots: " . $sbParams['max_snapshots'] . " Materialized Backups: " . $sbParams['maintain_materialized_copy'] . "\n"; break; case 'ROTATING': if ($sbParams['rotate_method'] == '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'); $rotateDays = explode(',', $sbParams['rotate_day_of_week']); $cron .= "# Day of week rotation on day(s): "; foreach ($rotateDays as $dayOfWeek) { $cron .= $dayList[$dayOfWeek] . " "; } $cron .= "\n"; } elseif ($sbParams['rotate_method'] == 'AFTER_SNAPSHOT_COUNT') { $cron .= "# After snapshot count rotation after " . $sbParams['rotate_snapshot_no'] . "\n"; } $cron .= "# Params Used: max_snapshot_groups: " . $sbParams['max_snapshot_groups'] . " Materialized Backups: " . $sbParams['maintain_materialized_copy'] . "\n"; break; default: break; } $cron .= $scheduledBackupInfo['cron_expression'] . ' ' . $XBM_AUTO_INSTALLDIR . '/xbm backup run ' . $hostInfo['hostname'] . ' ' . $scheduledBackupInfo['name'] . " quiet\n"; } else { continue; } } } return $cron; }