-
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-1372: Backup Critical Configuration Files to Recover On-Demand #115
MAGECLOUD-1372: Backup Critical Configuration Files to Recover On-Demand #115
Conversation
src/Command/BackupList.php
Outdated
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
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.
please remove empty line
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.
Fixed. Tanks.
src/Command/BackupList.php
Outdated
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
|
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.
please remove line
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.
Fixed.
src/Command/BackupList.php
Outdated
|
||
try { | ||
$output->writeln('<comment>The list of backup files:</comment>'); | ||
$output->writeln(array_keys($this->backupFilesList->getList())); |
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.
Maybe you should check if file is backup file really exists?
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.
Maybe...
src/Backup/Restorer.php
Outdated
* | ||
* @see \Magento\MagentoCloud\Filesystem\BackupList contains the list of files for restoring | ||
*/ | ||
class Restorer |
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.
Rename to Restore
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.
Done
src/Backup/Restorer.php
Outdated
$backupList = $this->backupList->getList(); | ||
|
||
if ($specificPath) { | ||
if (empty($backupList[$specificPath])) { |
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.
Move this check to restore()
method
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.
No, this we need this check only if a user wants to restore specific file.
/** | ||
* CLI command for restoring Magento configuration files from backup. | ||
*/ | ||
class BackupRestore extends Command |
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.
Move this to ../Command/Backup/Restore
namespace
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.
Done
src/Backup/Restorer.php
Outdated
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @param string $alias |
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.
Describe what does alias mean
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.
and better to change the order of arguments. I see that $alias may be not required when you cannot implement method without $file (file name)
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.
Done
src/Backup/Restorer.php
Outdated
* @param OutputInterface $output | ||
* @param string $alias | ||
* @param string $file | ||
*/ |
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 @return void
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.
There is @return in my locale code :)
src/Command/BackupList.php
Outdated
} catch (\Exception $exception) { | ||
$this->logger->critical($exception->getMessage()); | ||
|
||
throw $exception; |
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.
in the declaration this method should return only LogicException and only when this abstract method is not implemented
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.
So... we need to fix all our CLI commands...
src/Command/BackupRestore.php
Outdated
protected function configure() | ||
{ | ||
$this->setName(self::NAME) | ||
->setDescription('Restore important configuration files'); |
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.
Where may the user take info about which exactly important file will be restored?
As I see this command may be run without name of file, so all files will be restored, so it is important to make user know about what he is doing.
At least you need to forward the user to the command which can provide this information
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.
Fixed
/** | ||
* Command name | ||
*/ | ||
const NAME = 'backup:list'; |
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.
I see backup:list and backup:restore. Where is the command which creates these backups?
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 have a process that creates backups after deploy.
@@ -153,6 +153,10 @@ function () use ($root, $config) { | |||
$this->container->make(DeployProcess\CompressStaticContent::class), | |||
$this->container->make(DeployProcess\DisableGoogleAnalytics::class), | |||
$this->container->make(DeployProcess\UnlockCronJobs::class), | |||
/** | |||
* Remove this line after implementation post-deploy hook |
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.
then maybe add todo. And add this point to the ticket with post-deploy or even additional task is better
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.
Yes, I will create additional task
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.
src/Command/BackupList.php
Outdated
try { | ||
$output->writeln('<comment>The list of backup files:</comment>'); | ||
$output->writeln($this->backupFilesList->get() ?: 'There are no files in the backup'); | ||
return 0; |
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.
Please use constants, or don't return anything.
src/Command/BackupList.php
Outdated
return 0; | ||
} catch (\Exception $exception) { | ||
$this->logger->critical($exception->getMessage()); | ||
return 1; |
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.
Please use constant or throw an exception.
src/Command/BackupRestore.php
Outdated
. ' with option --force rewrite your existed files. Do you want to continue [y/N]?', | ||
false | ||
); | ||
$restore = $helper->ask($input, $output, $question); |
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.
Please move this into try-catch, ask
can throw an exception.
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.
Agree, fixed
src/Command/BackupRestore.php
Outdated
if ($restore) { | ||
$this->restore->run($input, $output); | ||
} | ||
return 0; |
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.
Replace with constant.
src/Command/BackupRestore.php
Outdated
$helper = $this->getHelper('question'); | ||
$question = new ConfirmationQuestion( | ||
'Command ' . self::NAME | ||
. ' with option --force rewrite your existed files. Do you want to continue [y/N]?', |
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.
change the text
... will rewrite ...
QA approved |
Description
After each redeploy will be created backup of configuration files: app/etc/config.php.bak app/etc/env.php.bak
If user removed or broke these files he can restore them using the next command:
./vendor/bin/ece-tools backup:restore
Also user can see available backup files using ./vendor/bin/ece-tools backup:list
Fixed Issues (if relevant)
https://magento2.atlassian.net/browse/MAGECLOUD-1372
Zephyr Tests
https://jira.corp.magento.com/browse/MAGETWO-85289
Contribution checklist