function getVolume()
 {
     $info = $this->getInfo();
     $volumeGetter = new volumeGetter();
     $volume = $volumeGetter->getById($info['backup_volume_id']);
     return $volume;
 }
 function handleVolumeActions($args)
 {
     // If we arent given any more parameters
     if (!isset($args[2])) {
         // Just output some helpful information and exit
         echo "Error: Action missing.\n\n";
         $this->printVolumeHelpText($args);
         return;
     }
     // Handle actions
     switch ($args[2]) {
         // Handle add
         case 'add':
             // Verify that we have all the params we need and they are OK.
             // Are they set..
             if (!isset($args[3]) || !isset($args[4])) {
                 // Input exception
                 throw new InputException("Error: Name and Path of Backup Volume to add must be given.\n\n  Example:\n\n\txbm " . $args[1] . ' add "Storage Array 1" /backup');
             }
             $volumeName = $args[3];
             $volumePath = rtrim($args[4], '/');
             $volumeGetter = new volumeGetter();
             $volumeGetter->setLogStream($this->log);
             // Get the new Volume
             $volume = $volumeGetter->getNew($volumeName, $volumePath);
             echo "Action: New volume created with name/path: " . $volumeName . " -- " . $volumePath . "\n\n";
             break;
             // Handle listing
         // Handle listing
         case 'list':
             $volumeGetter = new volumeGetter();
             $volumeGetter->setLogStream($this->log);
             $volumes = $volumeGetter->getAll();
             echo "-- Listing all Backup Volumes --\n\n";
             foreach ($volumes as $volume) {
                 $volumeInfo = $volume->getInfo();
                 echo "Name: " . $volumeInfo['name'] . "\tPath: " . $volumeInfo['path'] . "\n";
             }
             echo "\n\n";
             break;
             // Handle editing
         // Handle editing
         case 'edit':
             if (!isset($args[3]) || !isset($args[4]) || !isset($args[5])) {
                 $errMsg = "Error: Name of Backup Volume to edit must be given along with parameter and value.\n\n";
                 $errMsg .= "  Parameters:\n\n";
                 $errMsg .= "\tname - The name of the Backup Volume - Can be edited at any time.\n";
                 $errMsg .= "\tpath - The path of the Backup Volume - May only be edited if no Scheduled Backups are configured for the volume.\n\n";
                 $errMsg .= "  Example:\n\n\txbm " . $args[1] . ' edit "Storage Array 1" path /storage1';
                 throw new InputException($errMsg);
             }
             $volumeName = $args[3];
             $volumeParam = $args[4];
             $volumeValue = $args[5];
             $volumeGetter = new volumeGetter();
             $volumeGetter->setLogStream($this->log);
             if (!($volume = $volumeGetter->getByName($volumeName))) {
                 throw new ProcessingException("Error: No Backup Volume exists with name: " . $volumeName);
             }
             $volume->setParam($volumeParam, $volumeValue);
             echo "Action: Backup Volume: " . $volumeName . " parameter '" . $volumeParam . "' set to: " . $volumeValue . "\n\n";
             break;
             // Handle deleting
         // Handle deleting
         case 'delete':
             if (!isset($args[3])) {
                 throw new InputException("Error: Name of Backup Volume to delete must be given.");
             }
             $volumeName = $args[3];
             $volumeGetter = new volumeGetter();
             $volumeGetter->setLogStream($this->log);
             if (!($volume = $volumeGetter->getByName($volumeName))) {
                 throw new ProcessingException("Error: No Backup Volume exists with name: " . $volumeName);
             }
             $volume->delete();
             echo "Action: Backup Volume: " . $volumeName . " deleted.\n\n";
             break;
             // Handle unknown action
         // Handle unknown action
         default:
             echo "Error: Unrecognized action for " . $args[1] . " context: " . $args[2] . "\n\n";
             $this->printVolumeHelpText($args);
             break;
     }
     return;
 }
 function getNew($hostname, $name, $strategyCode, $cronExpression, $volumeName, $datadir, $mysqlUser, $mysqlPass)
 {
     $datadir = rtrim($datadir, '/');
     // Validate inputs
     host::validateHostname($hostname);
     scheduledBackup::validateName($name);
     backupStrategy::validateStrategyCode($strategyCode);
     scheduledBackup::validateCronExpression($cronExpression);
     backupVolume::validateName($volumeName);
     scheduledBackup::validateDatadirPath($datadir);
     scheduledBackup::validateMysqlUser($mysqlUser);
     scheduledBackup::validateMysqlPass($mysqlPass);
     // Lookup host by name
     $hostGetter = new hostGetter();
     $hostGetter->setLogStream($this->log);
     if (!($host = $hostGetter->getByName($hostname))) {
         throw new ProcessingException("Error: No Host could be found with a hostname matching: {$hostname}");
     }
     // Lookup volume by name
     $volumeGetter = new volumeGetter();
     $volumeGetter->setLogStream($this->log);
     if (!($volume = $volumeGetter->getByName($volumeName))) {
         throw new ProcessingException("Error: No Volume could be found with a name matching: {$volumeName}");
     }
     // Lookup backup strategy by code
     $strategyGetter = new backupStrategyGetter();
     $strategyGetter->setLogStream($this->log);
     if (!($strategy = $strategyGetter->getByCode($strategyCode))) {
         throw new ProcessingException("Error: No Backup Strategy could be found matching the code: {$strategyCode}");
     }
     // Check for existing scheduled backups with the same name for this host
     if ($existing = $this->getByHostnameAndName($hostname, $name)) {
         throw new ProcessingException("Error: A Scheduled Backup already exists for host {$hostname} with a name matching: {$name}");
     }
     // INSERT the row
     $conn = dbConnection::getInstance($this->log);
     // Create a new scheduledBackup entry
     // For now we just always create with "xtrabackup" binary used (mysql_type_id = 1)..
     // Maybe this can change later..
     $sql = "INSERT INTO scheduled_backups \n\t\t\t\t\t( name, cron_expression, datadir_path, mysql_user, mysql_password, \n\t\t\t\t\t  host_id, backup_volume_id, mysql_type_id, backup_strategy_id \n\t\t\t\t\t) VALUES ( \n\t\t\t\t\t\t'" . $conn->real_escape_string($name) . "',\n\t\t\t\t\t\t'" . $conn->real_escape_string($cronExpression) . "',\n\t\t\t\t\t\t'" . $conn->real_escape_string($datadir) . "',\n\t\t\t\t\t\t'" . $conn->real_escape_string($mysqlUser) . "',\n\t\t\t\t\t\t'" . $conn->real_escape_string($mysqlPass) . "',\n\t\t\t\t\t\t" . $host->id . ",\n\t\t\t\t\t\t" . $volume->id . ",\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t" . $strategy->id . "\n\t\t\t\t\t)";
     if (!$conn->query($sql)) {
         throw new DBException('scheduledBackupGetter->getNew: ' . "Error: Query: {$sql} \nFailed with MySQL Error: {$conn->error}");
     }
     // Init the object
     $scheduledBackup = new scheduledBackup($conn->insert_id);
     $scheduledBackup->setLogStream($this->log);
     // Init the default scheduledBackup parameters for the strategy
     $sql = "INSERT INTO scheduled_backup_params (scheduled_backup_id, backup_strategy_param_id, param_value) \n\t\t\t\t\t\tSELECT " . $scheduledBackup->id . ", backup_strategy_param_id, default_value \n\t\t\t\t\t\tFROM backup_strategy_params\n\t\t\t\t\t\tWHERE backup_strategy_id=" . $strategy->id;
     if (!$conn->query($sql)) {
         throw new DBException('scheduledBackupGetter->getNew: ' . "Error: Query: {$sql} \nFailed with MySQL Error: {$conn->error}");
     }
     return $scheduledBackup;
 }