Skip to content

Commit 927a565

Browse files
authored
MCLOUD-8063: ECE-Tools dump alternative location (#65)
1 parent df5cda1 commit 927a565

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

src/Command/DbDump.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class DbDump extends Command
2828
public const NAME = 'db-dump';
2929
public const ARGUMENT_DATABASES = 'databases';
3030
public const OPTION_REMOVE_DEFINERS = 'remove-definers';
31+
public const OPTION_DUMP_DIRECTORY = 'dump-directory';
3132

3233
/**
3334
* @var DumpProcessor
@@ -78,6 +79,12 @@ protected function configure(): void
7879
InputOption::VALUE_NONE,
7980
'Remove definers from the database dump'
8081
);
82+
$this->addOption(
83+
self::OPTION_DUMP_DIRECTORY,
84+
'a',
85+
InputOption:: VALUE_REQUIRED,
86+
'Use alternative directory for saving dump'
87+
);
8188

8289
parent::configure();
8390
}
@@ -116,7 +123,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
116123
$this->logger->info('Starting backup.');
117124
$this->dumpProcessor->execute(
118125
(bool)$input->getOption(self::OPTION_REMOVE_DEFINERS),
119-
$databases
126+
$databases,
127+
(string)$input->getOption(self::OPTION_DUMP_DIRECTORY)
120128
);
121129
$this->logger->info('Backup completed.');
122130
} catch (\Exception $exception) {

src/DB/DumpGenerator.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,20 @@ public function __construct(
8585
* @param string $database
8686
* @param ConnectionInterface $connectionData
8787
* @param bool $removeDefiners
88+
* @param string $alternativeDestination
8889
*
8990
* @throws UndefinedPackageException
9091
* @throws ShellException
9192
*/
92-
public function create(string $database, ConnectionInterface $connectionData, bool $removeDefiners)
93-
{
93+
public function create(
94+
string $database,
95+
ConnectionInterface $connectionData,
96+
bool $removeDefiners,
97+
string $alternativeDestination
98+
) {
9499
$dumpFileName = sprintf(self::DUMP_FILE_NAME_TEMPLATE, $database, time());
95-
$temporaryDirectory = sys_get_temp_dir();
100+
$temporaryDirectory = !empty($alternativeDestination) ? $alternativeDestination
101+
: $this->directoryList->getVar();
96102
$dumpFile = $temporaryDirectory . '/' . $dumpFileName;
97103
$lockFile = $this->directoryList->getVar() . '/' . self::LOCK_FILE_NAME;
98104

src/DB/DumpProcessor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ public function __construct(
126126
*
127127
* @param array $databases
128128
* @param bool $removeDefiners
129+
* @param string $alternativeDestination
129130
*
130131
* @throws ConfigException
131132
* @throws FileSystemException
132133
* @throws GenericException
133134
* @throws UndefinedPackageException
134135
*/
135-
public function execute(bool $removeDefiners, array $databases = [])
136+
public function execute(bool $removeDefiners, array $databases = [], string $alternativeDestination = '')
136137
{
137138
try {
138139
if (empty($databases)) {
@@ -157,7 +158,8 @@ public function execute(bool $removeDefiners, array $databases = [])
157158
$this->dumpGenerator->create(
158159
self::DATABASE_MAP[$connection],
159160
$this->connectionFactory->create($connection),
160-
$removeDefiners
161+
$removeDefiners,
162+
$alternativeDestination
161163
);
162164
}
163165
} finally {

src/Test/Functional/Acceptance/BackupDbCest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function partRunDbDumpWithoutSplitDbArch(CliTester $I)
118118
$this->expectedLogs,
119119
[
120120
'INFO: Start creation DB dump for main database...',
121-
'INFO: Finished DB dump for main database, it can be found here: /tmp/dump-main',
121+
'INFO: Finished DB dump for main database, it can be found here: /app/var/dump-main',
122122
]
123123
));
124124
$I->doNotSeeInOutput(['quote', 'sales']);
@@ -153,11 +153,11 @@ private function partRunDbDumpWithSplitDbArch(CliTester $I)
153153
$this->expectedLogs,
154154
[
155155
'INFO: Start creation DB dump for main database...',
156-
'INFO: Finished DB dump for main database, it can be found here: /tmp/dump-main',
156+
'INFO: Finished DB dump for main database, it can be found here: /app/var/dump-main',
157157
'INFO: Start creation DB dump for quote database...',
158-
'INFO: Finished DB dump for quote database, it can be found here: /tmp/dump-quote',
158+
'INFO: Finished DB dump for quote database, it can be found here: /app/var/dump-quote',
159159
'INFO: Start creation DB dump for sales database...',
160-
'INFO: Finished DB dump for sales database, it can be found here: /tmp/dump-sales',
160+
'INFO: Finished DB dump for sales database, it can be found here: /app/var/dump-sales',
161161
]
162162
));
163163

@@ -167,9 +167,9 @@ private function partRunDbDumpWithSplitDbArch(CliTester $I)
167167
$this->expectedLogs,
168168
[
169169
'INFO: Start creation DB dump for quote database...',
170-
'INFO: Finished DB dump for quote database, it can be found here: /tmp/dump-quote',
170+
'INFO: Finished DB dump for quote database, it can be found here: /app/var/dump-quote',
171171
'INFO: Start creation DB dump for sales database...',
172-
'INFO: Finished DB dump for sales database, it can be found here: /tmp/dump-sales',
172+
'INFO: Finished DB dump for sales database, it can be found here: /app/var/dump-sales',
173173
]
174174
));
175175
$I->doNotSeeInOutput('main');

src/Test/Unit/DB/DumpGeneratorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testCreate(bool $removeDefiners)
132132
$dumpFilePath,
133133
$removeDefiners
134134
));
135-
$this->dumpGenerator->create('main', $this->connectionDataMock, $removeDefiners);
135+
$this->dumpGenerator->create('main', $this->connectionDataMock, $removeDefiners, '');
136136
}
137137

138138
/**
@@ -173,7 +173,7 @@ public function testCreateWithException()
173173
))
174174
->willThrowException($exception);
175175
$this->expectExceptionObject($exception);
176-
$this->dumpGenerator->create('main', $this->connectionDataMock, false);
176+
$this->dumpGenerator->create('main', $this->connectionDataMock, false, '');
177177
}
178178

179179
public function testFailedCreationLockFile()
@@ -190,7 +190,7 @@ public function testFailedCreationLockFile()
190190
->with('Could not get the lock file!');
191191
$this->shellMock->expects($this->never())
192192
->method('execute');
193-
$this->dumpGenerator->create('main', $this->connectionDataMock, false);
193+
$this->dumpGenerator->create('main', $this->connectionDataMock, false, '');
194194
}
195195

196196
public function testLockedFile()
@@ -207,7 +207,7 @@ public function testLockedFile()
207207
);
208208
$this->shellMock->expects($this->never())
209209
->method('execute');
210-
$this->dumpGenerator->create('main', $this->connectionDataMock, false);
210+
$this->dumpGenerator->create('main', $this->connectionDataMock, false, '');
211211
}
212212

213213
private function getDumpFilePath(string $type): string

0 commit comments

Comments
 (0)