-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAGECLOUD-343: Method for exporting a DB Backup of production site #94
Merged
shiftedreality
merged 18 commits into
magento:develop
from
magento-thunder:MAGECLOUD-343
Nov 29, 2017
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d41528b
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS ce0ff01
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 5bf1d58
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 763a0a2
Merge branch 'develop' of github.com:magento/ece-tools into MAGECLOUD…
NadiyaS 238510c
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS a41b3b7
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS bb65c2e
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 4628bfb
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS d2a46aa
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 943de9f
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 80c2e9d
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 52fb015
Merge branch 'develop' of github.com:magento/ece-tools into MAGECLOUD…
NadiyaS 4342643
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 2579537
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 3bc4435
Merge branch 'develop' of github.com:magento/ece-tools into MAGECLOUD…
NadiyaS ee9c113
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 02a19e7
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS 41fa316
MAGECLOUD-343: Method for exporting a DB Backup of production site
NadiyaS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,69 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\MagentoCloud\Command; | ||
|
||
use Magento\MagentoCloud\Process\ProcessInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class DbDump for safely creating backup of database | ||
*/ | ||
class DbDump extends Command | ||
{ | ||
const NAME = 'db-dump'; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var ProcessInterface | ||
*/ | ||
private $process; | ||
|
||
/** | ||
* @param ProcessInterface $process | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct(ProcessInterface $process, LoggerInterface $logger) | ||
{ | ||
$this->process = $process; | ||
$this->logger = $logger; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName(self::NAME) | ||
->setDescription('Creates backup of database'); | ||
|
||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
try { | ||
$this->logger->info('Starting backup.'); | ||
$this->process->execute(); | ||
$this->logger->info('Backup completed.'); | ||
} catch (\Exception $exception) { | ||
$this->logger->critical($exception->getMessage()); | ||
|
||
throw $exception; | ||
} | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\MagentoCloud\DB\Data; | ||
|
||
/** | ||
* Database connection data interface | ||
*/ | ||
interface ConnectionInterface | ||
{ | ||
/** | ||
* Returns DB host name or IP address | ||
* | ||
* @return string | ||
*/ | ||
public function getHost(); | ||
|
||
/** | ||
* Returns TCP/IP port number to use for the connection | ||
* | ||
* @return int | ||
*/ | ||
public function getPort(); | ||
|
||
/** | ||
* Returns DB name | ||
* | ||
* @return string | ||
*/ | ||
public function getDbName(); | ||
|
||
/** | ||
* Returns user name for connecting to the server | ||
* | ||
* @return string | ||
*/ | ||
public function getUser(); | ||
|
||
/** | ||
* Returns password to use when connecting to the server | ||
* | ||
* @return string|null | ||
*/ | ||
public function getPassword(); | ||
} |
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,96 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\MagentoCloud\DB\Data; | ||
|
||
use Magento\MagentoCloud\Config\Environment; | ||
|
||
/** | ||
* Data for read only connection to database. | ||
* Should be used for backup or other read operations. | ||
*/ | ||
class ReadConnection implements ConnectionInterface | ||
{ | ||
/** | ||
* Resource of environment data | ||
* @var Environment | ||
*/ | ||
private $environment; | ||
|
||
/** | ||
* @param Environment $environment | ||
*/ | ||
public function __construct(Environment $environment) | ||
{ | ||
$this->environment = $environment; | ||
} | ||
|
||
/** | ||
* Checks whether project is integration or not. | ||
* | ||
* @return bool Return true if project is integration, otherwise return false (for staging or production) | ||
*/ | ||
private function isIntegration() | ||
{ | ||
//return empty($_ENV['REGISTRY']); | ||
//while $_ENV['REGISTRY'] is not approved by platform we check the DB host name | ||
//TODO: use method from Environment class which will be implemented in MAGECLOUD-1122 | ||
return $this->environment->getDbHost() === 'database.internal'; | ||
} | ||
|
||
/** | ||
* Returns the host name for backup. | ||
* Integration project has only one node and host should be used the same as retrieved from environment variables. | ||
* Production or staging projects have 3 nodes but for read operations we need to connect to localhost | ||
* with 3304 port and this connection will proxy to appropriate server. | ||
* | ||
* @return string | ||
*/ | ||
public function getHost() | ||
{ | ||
return $this->isIntegration() ? $this->environment->getDbHost() : '127.0.0.1'; | ||
} | ||
|
||
/** | ||
* Returns ports for DB connection for backup. | ||
* There are several available ports: | ||
* - 3306 - talks to master DB | ||
* - 3307 - talks to local node | ||
* - 3304 - is used for read only operations | ||
* For production or staging server we cannot make such operations as backup from active master, | ||
* so we should always use 3304 for them for localhost, this connection will proxy to appropriate server. | ||
* For integration we have only one node and 3306 is always used. | ||
* | ||
* @return int | ||
*/ | ||
public function getPort() | ||
{ | ||
return $this->isIntegration() ? 3306 : 3304; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getDbName() | ||
{ | ||
return $this->environment->getDbName(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getUser() | ||
{ | ||
return $this->environment->getDbUser(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getPassword() | ||
{ | ||
return $this->environment->getDbPassword(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add PHP strict types (
:int
,:string
, etc to all methods you introduced)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cannot add strict types to all methods as some of them can return several types. Also, we need to review class Environment which returns values of environment variables, because now almost all methods return string type even if the variable does not exist. And these changes may affect current Interface as it uses Environment class