Пример #1
0
 public static function onCreateBackupResult(Scalr_Messaging_Msg $message, DBServer $dbServer)
 {
     $dbFarmRole = $dbServer->GetFarmRoleObject();
     $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_LAST_TS, time(), DBFarmRole::TYPE_LCL);
     $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_IS_RUNNING, 0, DBFarmRole::TYPE_LCL);
     //$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_SERVER_ID, "");
     if (PlatformFactory::isOpenstack($dbServer->platform)) {
         $provider = 'cf';
     } else {
         switch ($dbServer->platform) {
             case SERVER_PLATFORMS::EC2:
                 $provider = 's3';
                 break;
             case SERVER_PLATFORMS::GCE:
                 $provider = 'gcs';
                 break;
             default:
                 $provider = 'unknown';
                 break;
         }
     }
     $backup = Scalr_Db_Backup::init();
     $backup->service = $message->dbType;
     $backup->platform = $dbServer->platform;
     $backup->provider = $provider;
     $backup->envId = $dbServer->envId;
     $backup->farmId = $dbServer->farmId;
     $backup->cloudLocation = $dbServer->GetCloudLocation();
     $backup->status = Scalr_Db_Backup::STATUS_AVAILABLE;
     $total = 0;
     if (isset($message->backupParts) && is_array($message->backupParts)) {
         foreach ($message->backupParts as $item) {
             if (is_object($item) && $item->size) {
                 $backup->addPart(str_replace(array("s3://", "cf://", "gcs://", "swift://"), array("", "", "", ""), $item->path), $item->size);
                 $total = $total + (int) $item->size;
             } else {
                 $backup->addPart(str_replace(array("s3://", "cf://", "gcs://", "swift://"), array("", "", "", ""), $item), 0);
             }
         }
     }
     $backup->size = $total;
     $backup->save();
 }
Пример #2
0
 public function xRemoveBackupAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_DB_BACKUPS, Acl::PERM_DB_BACKUPS_REMOVE);
     $backup = Scalr_Db_Backup::init()->loadById($this->getParam('backupId'));
     $this->user->getPermissions()->validate($backup);
     $backup->delete();
     $this->response->success('Backup successfully queued for removal.');
 }
Пример #3
0
 /**
  * Update database when 'mysqlBckComplete' event recieved from instance
  *
  * @param MysqlBackupCompleteEvent $event
  */
 public function OnMysqlBackupComplete(MysqlBackupCompleteEvent $event)
 {
     try {
         $DBFarmRole = $event->DBServer->GetFarmRoleObject();
         $farm_roleid = $DBfarmRole->ID;
     } catch (Exception $e) {
         return;
     }
     if ($event->Operation == MYSQL_BACKUP_TYPE::DUMP) {
         $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LAST_BCP_TS, time(), DBFarmRole::TYPE_LCL);
         $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_IS_BCP_RUNNING, 0, DBFarmRole::TYPE_LCL);
         switch ($event->DBServer->platform) {
             case SERVER_PLATFORMS::EC2:
                 $provider = 's3';
                 break;
             case SERVER_PLATFORMS::RACKSPACE:
                 $provider = 'cf';
                 break;
             default:
                 $provider = 'unknown';
                 break;
         }
         $backup = Scalr_Db_Backup::init();
         $backup->service = 'mysql';
         $backup->platform = $event->DBServer->platform;
         $backup->provider = $provider;
         $backup->envId = $event->DBServer->envId;
         $backup->farmId = $event->DBServer->farmId;
         $backup->cloudLocation = $event->DBServer->GetCloudLocation();
         $backup->status = Scalr_Db_Backup::STATUS_AVAILABLE;
         $total = 0;
         foreach ($event->backupParts as $item) {
             if (is_object($item) && $item->size) {
                 $backup->addPart(str_replace(array("s3://", "cf://"), array("", ""), $item->path), $item->size);
                 $total = $total + (int) $item->size;
             } else {
                 $backup->addPart(str_replace(array("s3://", "cf://"), array("", ""), $item), 0);
             }
         }
         $backup->size = $total;
         $backup->save();
     } elseif ($event->Operation == MYSQL_BACKUP_TYPE::BUNDLE) {
         $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LAST_BUNDLE_TS, time(), DBFarmRole::TYPE_LCL);
         $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_IS_BUNDLE_RUNNING, 0, DBFarmRole::TYPE_LCL);
         if (!is_array($event->SnapshotInfo)) {
             $event->SnapshotInfo = array('snapshotId' => $event->SnapshotInfo);
         }
         if ($event->SnapshotInfo['snapshotId']) {
             if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE) == MYSQL_STORAGE_ENGINE::EBS) {
                 $this->DB->Execute("INSERT INTO ebs_snaps_info SET snapid=?, comment=?, dtcreated=NOW(), region=?, ebs_array_snapid='0', is_autoebs_master_snap='1', farm_roleid=?", array($event->SnapshotInfo['snapshotId'], _('MySQL Master volume snapshot'), $event->DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION), $DBFarmRole->ID));
                 // Scalarizr stuff
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SNAPSHOT_ID, $event->SnapshotInfo['snapshotId'], DBFarmRole::TYPE_LCL);
                 $snapshotConfig = new stdClass();
                 $snapshotConfig->type = 'ebs';
                 $snapshotConfig->id = $event->SnapshotInfo['snapshotId'];
                 $event->SnapshotInfo['snapshotConfig'] = $snapshotConfig;
             }
         }
         if ($event->SnapshotInfo['logFile']) {
             $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE, $event->SnapshotInfo['logFile'], DBFarmRole::TYPE_LCL);
         }
         if ($event->SnapshotInfo['logPos']) {
             $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS, $event->SnapshotInfo['logPos'], DBFarmRole::TYPE_LCL);
         }
         try {
             $storageSnapshot = Scalr_Storage_Snapshot::init();
             $storageSnapshot->loadBy(array('id' => $event->SnapshotInfo['snapshotConfig']->id, 'client_id' => $event->DBServer->clientId, 'farm_id' => $event->DBServer->farmId, 'farm_roleid' => $event->DBServer->farmRoleId, 'env_id' => $event->DBServer->envId, 'name' => sprintf(_("MySQL data bundle #%s"), $event->SnapshotInfo['snapshotConfig']->id), 'type' => $DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE), 'platform' => $event->DBServer->platform, 'description' => sprintf(_("MySQL data bundle created on Farm '%s' -> Role '%s'"), $DBFarmRole->GetFarmObject()->Name, $DBFarmRole->GetRoleObject()->name), 'ismysql' => true, 'service' => ROLE_BEHAVIORS::MYSQL));
             $storageSnapshot->setConfig($event->SnapshotInfo['snapshotConfig']);
             $storageSnapshot->save(true);
             $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SCALR_SNAPSHOT_ID, $storageSnapshot->id, DBFarmRole::TYPE_LCL);
         } catch (Exception $e) {
             $this->Logger->fatal("Cannot save storage snapshot: {$e->getMessage()}");
         }
     }
 }