-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from pjcdawkins/rename-backup-snapshot
Rename 'backup' to 'snapshot'
- Loading branch information
Showing
9 changed files
with
198 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
namespace Platformsh\Cli\Command\Snapshot; | ||
|
||
use Platformsh\Cli\Command\PlatformCommand; | ||
use Platformsh\Cli\Util\ActivityUtil; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class SnapshotCreateCommand extends PlatformCommand | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setName('snapshot:create') | ||
->setHiddenAliases(array('backup', 'environment:backup')) | ||
->setDescription('Make a snapshot of an environment') | ||
->addArgument('environment', InputArgument::OPTIONAL, 'The environment') | ||
->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the snapshot to complete'); | ||
$this->addProjectOption() | ||
->addEnvironmentOption(); | ||
$this->setHelp('See https://docs.platform.sh/use-platform/backup-and-restore.html'); | ||
$this->addExample('Make a snapshot of the current environment'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->validateInput($input); | ||
|
||
$selectedEnvironment = $this->getSelectedEnvironment(); | ||
$environmentId = $selectedEnvironment['id']; | ||
if (!$selectedEnvironment->operationAvailable('backup')) { | ||
$this->stdErr->writeln( | ||
"Operation not available: cannot create a snapshot of <error>$environmentId</error>" | ||
); | ||
|
||
return 1; | ||
} | ||
|
||
$activity = $selectedEnvironment->backup(); | ||
|
||
$this->stdErr->writeln("Creating a snapshot of <info>$environmentId</info>"); | ||
|
||
if (!$input->getOption('no-wait')) { | ||
$success = ActivityUtil::waitAndLog( | ||
$activity, | ||
$this->stdErr, | ||
"A snapshot of environment <info>$environmentId</info> has been created", | ||
"The snapshot failed" | ||
); | ||
if (!$success) { | ||
return 1; | ||
} | ||
} | ||
|
||
if (!empty($activity['payload']['backup_name'])) { | ||
$name = $activity['payload']['backup_name']; | ||
$output->writeln("Snapshot name: <info>$name</info>"); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
namespace Platformsh\Cli\Command\Snapshot; | ||
|
||
use Platformsh\Cli\Command\PlatformCommand; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class SnapshotListCommand extends PlatformCommand | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setName('snapshot:list') | ||
->setAliases(array('snapshots')) | ||
->setDescription('List available snapshots of an environment') | ||
->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'Limit the number of snapshots to list', 10); | ||
$this->addProjectOption() | ||
->addEnvironmentOption(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->validateInput($input); | ||
|
||
$environment = $this->getSelectedEnvironment(); | ||
|
||
$stdErr = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; | ||
|
||
$stdErr->writeln("Finding snapshots for the environment <info>{$environment['id']}</info>"); | ||
$results = $environment->getActivities($input->getOption('limit'), 'environment.backup'); | ||
if (!$results) { | ||
$stdErr->writeln('No snapshots found'); | ||
return 1; | ||
} | ||
|
||
$headers = array("Created", "% Complete", "Snapshot name"); | ||
$rows = array(); | ||
foreach ($results as $result) { | ||
$payload = $result->getProperty('payload'); | ||
$snapshot_name = !empty($payload['backup_name']) ? $payload['backup_name'] : 'N/A'; | ||
$rows[] = array( | ||
date('Y-m-d H:i:s', strtotime($result->getProperty('created_at'))), | ||
$result->getCompletionPercent(), | ||
$snapshot_name, | ||
); | ||
} | ||
|
||
$table = new Table($output); | ||
$table->setHeaders($headers); | ||
$table->setRows($rows); | ||
$table->render(); | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.