Skip to content

Commit 23c56a0

Browse files
Merge branch 'master' into 6.0
2 parents 1ba5c8a + b6e48c2 commit 23c56a0

File tree

15 files changed

+924
-0
lines changed

15 files changed

+924
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ If you are behind php 7.0 you can still use phpbu version [4.0.10](https://phar.
2626
+ Directories
2727
+ Elasticsearch
2828
+ InfluxDB
29+
+ Ldap
2930
+ MongoDB
3031
+ MySQL
3132
+ Percona XtraBackup

doc/config/source/ldapdump.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "ldapdump",
3+
"options": {
4+
"host": "localhost",
5+
"port": "389",
6+
"searchBase": "ou=Users,dc=fr",
7+
"filter": "(objectclass=*)",
8+
"attrs": "*",
9+
"pathToLdapdump": "/path/to/custom/bin"
10+
}
11+
}

doc/config/source/ldapdump.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<source type="influxdump">
3+
<!-- optional, default=localhost -->
4+
<option name="host" value="localhost" />
5+
6+
<!-- optional, default=389 -->
7+
<option name="port" value="389" />
8+
9+
<!-- optional -->
10+
<option name="searchBase" value="ou=Users,dc=fr" />
11+
12+
<!-- optional -->
13+
<option name="filter" value="(objectclass=*)" />
14+
15+
<!-- optional -->
16+
<option name="attrs" value="*" />
17+
18+
<!-- define your custom ldapdump executable location -->
19+
<option name="pathToInfluxdump" value="/path/to/custom/bin" />
20+
</source>

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/Ldapdump.php

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
3+
namespace phpbu\App\Backup\Source;
4+
5+
use phpbu\App\Backup\Target;
6+
use phpbu\App\Cli\Executable;
7+
use phpbu\App\Exception;
8+
use phpbu\App\Result;
9+
use phpbu\App\Util;
10+
11+
/**
12+
* Ldapdump source class.
13+
*
14+
* @package phpbu
15+
* @subpackage Backup
16+
* @author Sebastian Feldmann <[email protected]>
17+
* @author Julian Marié <[email protected]>
18+
* @copyright Sebastian Feldmann <[email protected]>
19+
* @license https://opensource.org/licenses/MIT The MIT License (MIT)
20+
* @link http://phpbu.de/
21+
* @since Class available since Release 2.1.12
22+
*/
23+
class Ldapdump extends SimulatorExecutable implements Simulator
24+
{
25+
/**
26+
* Executable to handle ldapDb command.
27+
*
28+
* @var \phpbu\App\Cli\Executable\Ldapdump
29+
*/
30+
protected $executable;
31+
32+
/**
33+
* Path to executable.
34+
*
35+
* @var string $pathToLdapdump
36+
*/
37+
private $pathToLdapdump;
38+
39+
/**
40+
* Host to connect to
41+
* -h <hostname>
42+
*
43+
* @var string $host
44+
*/
45+
private $host;
46+
47+
/**
48+
* Port to connect to
49+
* -p <port>
50+
*
51+
* @var string $port
52+
*/
53+
private $port;
54+
55+
/**
56+
* Basename
57+
* -b <basename>
58+
*
59+
* @var string $searchBase
60+
*/
61+
private $searchBase;
62+
63+
/**
64+
* BindDn to connect with
65+
* -D <DN>
66+
*
67+
* @var string $bindDn
68+
*/
69+
private $bindDn;
70+
71+
/**
72+
* Password to authenticate with
73+
* -w <password>
74+
*
75+
* @var string $password
76+
*/
77+
private $password;
78+
79+
/**
80+
* Filter
81+
* <filter>
82+
*
83+
* @var string $filter
84+
*/
85+
private $filter;
86+
87+
/**
88+
* Attributes
89+
* <attrs>
90+
*
91+
* @var array $attrs
92+
*/
93+
private $attrs;
94+
95+
/**
96+
* Setup.
97+
*
98+
* @see \phpbu\App\Backup\Source
99+
* @param array $conf
100+
* @throws \phpbu\App\Exception
101+
*/
102+
public function setup(array $conf = [])
103+
{
104+
$this->setupSourceData($conf);
105+
106+
$this->pathToLdapdump = Util\Arr::getValue($conf, 'pathToLdapdump', '');
107+
$this->host = Util\Arr::getValue($conf, 'host', '');
108+
$this->port = Util\Arr::getValue($conf, 'port', 0);
109+
$this->searchBase = Util\Arr::getValue($conf, 'searchBase', '');
110+
$this->bindDn = Util\Arr::getValue($conf, 'bindDn', '');
111+
$this->password = Util\Arr::getValue($conf, 'password', '');
112+
$this->filter = Util\Arr::getValue($conf, 'filter', '');
113+
}
114+
115+
/**
116+
* Get attributes to backup
117+
*
118+
* @param array $conf
119+
*/
120+
protected function setupSourceData(array $conf)
121+
{
122+
$this->attrs = Util\Str::toList(Util\Arr::getValue($conf, 'attrs', ''));
123+
}
124+
125+
/**
126+
* Execute the backup.
127+
*
128+
* @see \phpbu\App\Backup\Source
129+
* @param \phpbu\App\Backup\Target $target
130+
* @param \phpbu\App\Result $result
131+
* @return \phpbu\App\Backup\Source\Status
132+
* @throws \phpbu\App\Exception
133+
*/
134+
public function backup(Target $target, Result $result) : Status
135+
{
136+
$ldapdb = $this->execute($target);
137+
138+
$result->debug($this->getExecutable($target)->getCommandPrintable());
139+
140+
if (!$ldapdb->isSuccessful()) {
141+
throw new Exception('ldapdb dump failed:' . $ldapdb->getStdErr());
142+
}
143+
144+
return $this->createStatus($target);
145+
}
146+
147+
/**
148+
* Create the Executable to run the ldapdump command.
149+
*
150+
* @param \phpbu\App\Backup\Target $target
151+
* @return \phpbu\App\Cli\Executable
152+
*/
153+
protected function createExecutable(Target $target) : Executable
154+
{
155+
$executable = new Executable\Ldapdump($this->pathToLdapdump);
156+
$executable
157+
->credentials($this->bindDn, $this->password)
158+
->useHost($this->host)
159+
->usePort((int) $this->port)
160+
->useSearchBase($this->searchBase)
161+
->useFilter($this->filter)
162+
->useAttributes($this->attrs)
163+
->dumpTo($this->getDumpTarget($target));
164+
// if compression is active and commands can be piped
165+
if ($this->isHandlingCompression($target)) {
166+
$executable->compressOutput($target->getCompression());
167+
}
168+
169+
return $executable;
170+
}
171+
172+
/**
173+
* Create backup status.
174+
*
175+
* @param \phpbu\App\Backup\Target $target
176+
* @return \phpbu\App\Backup\Source\Status
177+
*/
178+
protected function createStatus(Target $target) : Status
179+
{
180+
// if compression is active and commands can be piped
181+
// compression is handled via pipe
182+
if ($this->isHandlingCompression($target)) {
183+
return Status::create();
184+
}
185+
186+
// default create uncompressed dump file
187+
return Status::create()->uncompressedFile($this->getDumpTarget($target));
188+
}
189+
190+
/**
191+
* Can compression be handled via pipe operator.
192+
*
193+
* @param \phpbu\App\Backup\Target $target
194+
* @return bool
195+
*/
196+
private function isHandlingCompression(Target $target) : bool
197+
{
198+
return $target->shouldBeCompressed() && Util\Cli::canPipe() && $target->getCompression()->isPipeable();
199+
}
200+
201+
/**
202+
* Return dump target path.
203+
*
204+
* @param \phpbu\App\Backup\Target $target
205+
* @return string
206+
*/
207+
private function getDumpTarget(Target $target) : string
208+
{
209+
return $target->getPathnamePlain();
210+
}
211+
}

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)

0 commit comments

Comments
 (0)