public function restoreBackup($site_env, array $options = ['file' => null, 'element' => null])
{
list($site, $env) = $this->getSiteEnv($site_env);
if (isset($options['file']) && !is_null($file_name = $options['file'])) {
$backup = $env->getBackups()->getBackupByFileName($file_name);
} else {
$element = $options['element'] == 'db' ? 'database' : $options['element'];
$backups = $env->getBackups()->getFinishedBackups($element);
if (empty($backups)) {
throw new TerminusNotFoundException('No backups available. Create one with `terminus backup:create {site}.{env}`', ['site' => $site->get('name'), 'env' => $env->id]);
}
$backup = array_shift($backups);
}
$workflow = $backup->restore();
$workflow->wait();
if ($workflow->isSuccessful()) {
$this->log()->notice('Restored the backup to {env}.', ['env' => $env->id]);
} else {
$message = $workflow->getMessage();
if (trim($message) == 'Successfully queued restore_site') {
$message = 'There was an error while restoring your backup.';
}
throw new TerminusException($message);
}
}