Skip to content

Commit 09c698c

Browse files
Merge pull request #230 from angelfs
Add ssl-ca option to mysqldump
2 parents 5ef79f9 + 540dac3 commit 09c698c

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

doc/config/source/mysqldump.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"skipTriggers": false,
1919
"routines": true,
2020
"gtidPurged": "AUTO",
21+
"sslCa": "/var/www/html/BaltimoreCyberTrustRoot.crt.pem",
2122
"pathToMysqldump": "/path/to/custom/bin"
2223
}
2324
}

doc/config/source/mysqldump.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
<!-- optional, default=none, accepted=ON,OFF,AUTO -->
5252
<option name="gtidPurged" value="ON" />
5353

54+
<!-- optional, default=none -->
55+
<option name="sslCa" value="/var/www/html/BaltimoreCyberTrustRoot.crt.pem" />
56+
5457
<!-- define your custom mysqldump executable location -->
5558
<option name="pathToMysqldump" value="/path/to/custom/bin" />
5659
</source>

src/Backup/Source/Mysqldump.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ class Mysqldump extends SimulatorExecutable implements Simulator, Restorable
184184
*/
185185
private $gtidPurged;
186186

187+
/**
188+
* SSL CA
189+
* --ssl-ca
190+
*
191+
* @var string
192+
*/
193+
private $sslCa;
194+
187195
/**
188196
* Dump procedures and functions
189197
* --routines
@@ -220,6 +228,7 @@ public function setup(array $conf = [])
220228
$this->user = Util\Arr::getValue($conf, 'user', '');
221229
$this->password = Util\Arr::getValue($conf, 'password', '');
222230
$this->gtidPurged = Util\Arr::getValue($conf, 'gtidPurged', '');
231+
$this->sslCa = Util\Arr::getValue($conf, 'sslCa', '');
223232
$this->hexBlob = Util\Str::toBoolean(Util\Arr::getValue($conf, 'hexBlob', ''), false);
224233
$this->quick = Util\Str::toBoolean(Util\Arr::getValue($conf, 'quick', ''), false);
225234
$this->lockTables = Util\Str::toBoolean(Util\Arr::getValue($conf, 'lockTables', ''), false);
@@ -331,6 +340,7 @@ protected function createExecutable(Target $target) : Executable
331340
->lockTables($this->lockTables)
332341
->dumpBlobsHexadecimal($this->hexBlob)
333342
->addGTIDStatement($this->gtidPurged)
343+
->useSslCa($this->sslCa)
334344
->useCompression($this->compress)
335345
->skipExtendedInsert($this->skipExtendedInsert)
336346
->dumpTables($this->tables)

src/Cli/Executable/Mysqldump.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ class Mysqldump extends Abstraction implements Executable
140140
*/
141141
private $gtidPurged;
142142

143+
/**
144+
* SSL CA
145+
* --ssl-ca
146+
*
147+
* @var string
148+
*/
149+
private $sslCa;
150+
143151
/**
144152
* Table separated data files
145153
* --tab
@@ -399,6 +407,18 @@ public function addGTIDStatement(string $purge)
399407
return $this;
400408
}
401409

410+
/**
411+
* Allow to use SSL CA option
412+
*
413+
* @param string $sslCa
414+
* @return \phpbu\App\Cli\Executable\Mysqldump
415+
*/
416+
public function useSslCa(string $sslCa)
417+
{
418+
$this->sslCa = $sslCa;
419+
return $this;
420+
}
421+
402422
/**
403423
* Produce table separated data files
404424
*
@@ -483,6 +503,7 @@ protected function createCommandLine() : CommandLine
483503
$cmd->addOptionIfNotEmpty('--skip-extended-insert', $this->skipExtendedInsert, false);
484504
$cmd->addOptionIfNotEmpty('--hex-blob', $this->hexBlob, false);
485505
$cmd->addOptionIfNotEmpty('--set-gtid-purged', $this->gtidPurged);
506+
$cmd->addOptionIfNotEmpty('--ssl-ca', $this->sslCa);
486507
$cmd->addOptionIfNotEmpty('--routines', $this->routines, false);
487508
$cmd->addOptionIfNotEmpty('--skip-triggers', $this->skipTriggers, false);
488509

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ public function testGtidPurged()
150150
);
151151
}
152152

153+
/**
154+
* Tests Mysqldump::getExecutable
155+
*/
156+
public function testSslCa()
157+
{
158+
$target = $this->createTargetMock('/tmp/foo');
159+
$mysqldump = new Mysqldump();
160+
$mysqldump->setup(['pathToMysqldump' => PHPBU_TEST_BIN, 'sslCa' => '/var/www/html/BaltimoreCyberTrustRoot.crt.pem']);
161+
162+
$executable = $mysqldump->getExecutable($target);
163+
164+
$this->assertEquals(
165+
PHPBU_TEST_BIN . '/mysqldump --ssl-ca=\'/var/www/html/BaltimoreCyberTrustRoot.crt.pem\' --all-databases > /tmp/foo',
166+
$executable->getCommand()
167+
);
168+
}
169+
153170
/**
154171
* Tests Mysqldump::getExecutable
155172
*/

tests/phpbu/Cli/Executable/MysqldumpTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ public function testGTIDInvalid()
254254
);
255255
}
256256

257+
/**
258+
* Tests Mysqldump::getCommand
259+
*/
260+
public function testUseSslCa()
261+
{
262+
$mysqldump = new Mysqldump(PHPBU_TEST_BIN);
263+
$mysqldump->useSslCa('/var/www/html/BaltimoreCyberTrustRoot.crt.pem');
264+
$cmd = $mysqldump->getCommand();
265+
266+
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --ssl-ca=\'/var/www/html/BaltimoreCyberTrustRoot.crt.pem\' --all-databases', $cmd);
267+
}
268+
257269
/**
258270
* Tests Mysqldump::getCommand
259271
*/

0 commit comments

Comments
 (0)