function getBackupStrategy()
 {
     $info = $this->getInfo();
     $backupStrategyGetter = new backupStrategyGetter();
     $backupStrategyGetter->setLogStream($this->log);
     $strat = $backupStrategyGetter->getById($info['backup_strategy_id']);
     return $strat;
 }
 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;
 }