/** * Helper function to get the S3 backup URL. * * @param string $site_name * The machine name of the Site in question. * @param string $env_name * The machine name of the Site Environment in question. * @param string $bucket * The S3 bucket. * @param string $element * Elements are db, code, files. * * @return string * The S3 URL of the backup. */ public function apiGetBackupDownloadUrl($site_name, $env_name, $bucket, $element) { $site = SiteQuery::create()->filterByProvider($this->name)->filterByName($site_name)->findOne(); $result = switchboard_request($this, array('method' => 'POST', 'resource' => 'site', 'realm' => 'environments/' . $env_name . '/backups/catalog/' . $bucket . '/' . $element . '/s3token', 'uuid' => $site->getUuid(), 'data' => array('method' => 'GET'))); $token = json_decode($result->body); return $token->url; }
/** * Get a list of database backups for a particular Site Environment. * * @param string $site_name * The machine name of the Site. * @param string $env_name * The machine name of the Site Environment. * @param string $backup_type * The type of backup. * * @return array * An array of Backup arrays keyed by the timestamp. Each Backup * array has the following keys: * - 'filename' * - 'url' * - 'timestamp' */ public function apiGetSiteEnvBackups($site_name, $env_name, $backup_type) { $site = SiteQuery::create()->filterByProvider($this->name)->filterByName($site_name)->findOne(); if ($backup_type == 'db') { $result = switchboard_request($this, array('method' => 'GET', 'resource' => '/sites/' . $site->getRealm() . ':' . $site_name . '/envs/' . $env_name . '/dbs/' . $site_name . '/backups')); } $backup_data = json_decode($result->body); $backups = array(); foreach ($backup_data as $backup) { $backups[$backup->completed] = array('filename' => end(explode('/', $backup->path)), 'url' => '', 'timestamp' => $backup->completed, 'id' => $backup->id); } arsort($backups); return $backups; }