Skip to content

Commit a76d6e0

Browse files
Merge branch 'main' of into 6.0
2 parents 92f81b8 + a14fe57 commit a76d6e0

File tree

11 files changed

+141
-10
lines changed

11 files changed

+141
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ before_script:
1212
- if [ $TRAVIS_PHP_VERSION = "7.4" ]; then wget -O phpstan.phar https://github.com/phpstan/phpstan/releases/download/0.12.18/phpstan.phar ; fi
1313

1414
script:
15-
- php phpunit.phar --configuration ./build/travis-ci.phpunit.xml
15+
- XDEBUG_MODE=coverage php phpunit.phar --configuration ./build/travis-ci.phpunit.xml
1616
- if [ $TRAVIS_PHP_VERSION = "7.4" ]; then php phpstan.phar analyse --no-progress -c phpstan.neon; fi
1717

1818
notifications:

doc/config/source/pgdump.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"options": {
44
"host": "localhost",
55
"port": "1234",
6+
"jobs": "4",
67
"user": "myUserName",
78
"password": "topSecret",
89
"database": "myDatabaseName",

doc/config/source/pgdump.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<!-- optional, default none -->
77
<option name="port" value="1234" />
88

9+
<!-- optional, default none -->
10+
<option name="jobs" value="4" />
11+
912
<!-- optional, default none -->
1013
<option name="user" value="myUserName" />
1114

src/Backup/Source/Pgdump.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ class Pgdump extends SimulatorExecutable implements Simulator
5050
*/
5151
private $port;
5252

53+
/**
54+
* Run the dump in parallel by dumping njobs tables simultaneously.
55+
* Reduces the time of the dump but it also increases the load on the database server.
56+
* --jobs=<NJobs>
57+
*
58+
* @var int
59+
*/
60+
private $jobs;
61+
5362
/**
5463
* User to connect with
5564
* --user=<username>
@@ -169,6 +178,14 @@ class Pgdump extends SimulatorExecutable implements Simulator
169178
*/
170179
private $noPrivileges;
171180

181+
/**
182+
* Set SSL mode
183+
* PGSSLMODE=allow pg_dump ...
184+
*
185+
* @var string
186+
*/
187+
private $sslMode;
188+
172189
/**
173190
* Setup
174191
*
@@ -196,6 +213,7 @@ private function setupConnection(array $conf)
196213
$this->port = Util\Arr::getValue($conf, 'port', 0);
197214
$this->user = Util\Arr::getValue($conf, 'user', '');
198215
$this->password = Util\Arr::getValue($conf, 'password', '');
216+
$this->sslMode = Util\Arr::getValue($conf, 'sslMode', '');
199217
}
200218

201219
/**
@@ -227,6 +245,7 @@ private function setupDumpOptions(array $conf)
227245
$this->noOwner = Util\Str::toBoolean(Util\Arr::getValue($conf, 'noOwner', ''), false);
228246
$this->encoding = Util\Arr::getValue($conf, 'encoding', '');
229247
$this->format = Util\Arr::getValue($conf, 'format', self::DEFAULT_FORMAT);
248+
$this->jobs = Util\Arr::getValue($conf, 'jobs', 0);
230249
}
231250

232251

@@ -264,6 +283,7 @@ protected function createExecutable(Target $target) : Executable
264283
$executable->credentials($this->user, $this->password)
265284
->useHost($this->host)
266285
->usePort($this->port)
286+
->sslMode($this->sslMode)
267287
->dumpDatabase($this->database)
268288
->dumpSchemas($this->schemas)
269289
->excludeSchemas($this->excludeSchemas)
@@ -275,6 +295,7 @@ protected function createExecutable(Target $target) : Executable
275295
->dumpNoPrivileges($this->noPrivileges)
276296
->dumpNoOwner($this->noOwner)
277297
->dumpFormat($this->format)
298+
->dumpJobs($this->jobs)
278299
->dumpTo($target->getPathnamePlain());
279300
return $executable;
280301
}

src/Cli/Executable/Pgdump.php

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ class Pgdump extends Abstraction implements Executable
3636
* @var int
3737
*/
3838
private $port;
39+
40+
/**
41+
* Run the dump in parallel by dumping njobs tables simultaneously.
42+
* --jobs=njobs
43+
* @var int
44+
*/
45+
private $jobs;
46+
47+
/**
48+
* Set SSL mode
49+
* PGSSLMODE=allow pg_dump ...
50+
*
51+
* @var string
52+
*/
53+
private $sslMode;
3954

4055
/**
4156
* User to connect with
@@ -172,7 +187,7 @@ class Pgdump extends Abstraction implements Executable
172187
* @var string
173188
*/
174189
private $file;
175-
190+
176191
/**
177192
* List of available output formats
178193
*
@@ -189,6 +204,20 @@ class Pgdump extends Abstraction implements Executable
189204
'tar' => true,
190205
];
191206

207+
/**
208+
* List of available sslmode
209+
*
210+
* @var array
211+
*/
212+
private $availableSslMode = [
213+
'disable' => true,
214+
'allow' => true,
215+
'prefer' => true,
216+
'require' => true,
217+
'verify-ca' => true,
218+
'verify-full' => true,
219+
];
220+
192221
/**
193222
* Constructor.
194223
*
@@ -238,6 +267,36 @@ public function usePort(int $port) : Pgdump
238267
return $this;
239268
}
240269

270+
/**
271+
* Define njobs tables simultaneously..
272+
*
273+
* @param int $jobs
274+
* @return \phpbu\App\Cli\Executable\Pgdump
275+
*/
276+
public function dumpJobs(int $jobs): Pgdump
277+
{
278+
if ($jobs < 0) {
279+
throw new Exception('invalid jobs value');
280+
}
281+
$this->jobs = $jobs;
282+
return $this;
283+
}
284+
285+
/**
286+
* Set the sslmode
287+
*
288+
* @param string $sslMode
289+
* @return Pgdump
290+
*/
291+
public function sslMode(string $sslMode): Pgdump
292+
{
293+
if ($sslMode && !isset($this->availableSslMode[$sslMode])) {
294+
throw new Exception('invalid sslMode');
295+
}
296+
$this->sslMode = $sslMode;
297+
return $this;
298+
}
299+
241300
/**
242301
* Set database to dump.
243302
*
@@ -454,7 +513,8 @@ protected function createCommandLine() : CommandLine
454513
{
455514
$process = new CommandLine();
456515
$password = $this->password ? 'PGPASSWORD=' . escapeshellarg($this->password) . ' ' : '';
457-
$cmd = new Cmd($password . $this->binary);
516+
$sslMode = $this->sslMode ? 'PGSSLMODE=' . escapeshellarg($this->sslMode) . ' ' : '';
517+
$cmd = new Cmd($sslMode . $password . $this->binary);
458518
$process->addCommand($cmd);
459519

460520
// always disable password prompt
@@ -463,6 +523,7 @@ protected function createCommandLine() : CommandLine
463523
$cmd->addOptionIfNotEmpty('--username', $this->user);
464524
$cmd->addOptionIfNotEmpty('--host', $this->host);
465525
$cmd->addOptionIfNotEmpty('--port', $this->port);
526+
$cmd->addOptionIfNotEmpty('--jobs', $this->jobs);
466527
$cmd->addOptionIfNotEmpty('--dbname', $this->databaseToDump);
467528
$cmd->addOptionIfNotEmpty('--schema-only', $this->schemaOnly, false);
468529
$cmd->addOptionIfNotEmpty('--data-only', $this->dataOnly, false);
@@ -471,6 +532,7 @@ protected function createCommandLine() : CommandLine
471532
$cmd->addOptionIfNotEmpty('--encoding', $this->encoding);
472533
$cmd->addOptionIfNotEmpty('--no-tablespaces', $this->noTablespaces, false);
473534
$cmd->addOptionIfNotEmpty('--no-acl', $this->noPrivileges, false);
535+
474536

475537
$this->handleSchemas($cmd);
476538
$this->handleTables($cmd);

tests/phpbu/Backup/Source/InfluxdumpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function testBackupFail()
115115
try {
116116
$influxd->backup($target, $appResult);
117117
} catch (Exception $e) {
118-
$this->assertFileDoesNotExist($file);
118+
$this->assertFileNotExists($file);
119119
throw $e;
120120
}
121121
}

tests/phpbu/Backup/Source/LdapdumpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testBackupFail()
200200
try {
201201
$ldap->backup($target, $appResult);
202202
} catch (Exception $e) {
203-
$this->assertFileDoesNotExist($file);
203+
$this->assertFileNotExists($file);
204204
throw $e;
205205
}
206206
}

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public function testBackupFail()
338338
try {
339339
$mysqldump->backup($target, $appResult);
340340
} catch (Exception $e) {
341-
$this->assertFileDoesNotExist($file);
341+
$this->assertFileNotExists($file);
342342
throw $e;
343343
}
344344
}

tests/phpbu/Backup/Source/PgdumpTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ public function testDefault()
3838
);
3939
}
4040

41+
/**
42+
* Tests Pgdump::getExecutable
43+
*/
44+
public function testSslMode()
45+
{
46+
$target = $this->createTargetMock('foo.sql');
47+
$pgDump = new Pgdump();
48+
$pgDump->setup(['pathToPgdump' => PHPBU_TEST_BIN, 'sslMode' => 'require']);
49+
50+
$executable = $pgDump->getExecutable($target);
51+
52+
$this->assertEquals(
53+
'PGSSLMODE=\'require\' ' . PHPBU_TEST_BIN . '/pg_dump -w --file=\'foo.sql\' --format=\'p\'',
54+
$executable->getCommand()
55+
);
56+
}
57+
4158
/**
4259
* Tests Pgdump::getExecutable
4360
*/

tests/phpbu/Cli/Executable/PgdumpTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,33 @@ public function testEncoding()
251251
);
252252
}
253253

254+
/**
255+
* Tests Pgdump::getCommand
256+
*/
257+
public function testJobs()
258+
{
259+
$file = '/tmp/foo';
260+
$pgdump = new Pgdump(PHPBU_TEST_BIN);
261+
$pgdump->dumpDatabase('phpbu')->dumpJobs(4)->dumpTo($file);
262+
263+
$this->assertEquals(
264+
PHPBU_TEST_BIN . '/pg_dump -w --jobs=\'4\' --dbname=\'phpbu\' --file=\'/tmp/foo\'',
265+
$pgdump->getCommand()
266+
);
267+
}
268+
269+
/**
270+
* Tests Pgdump::getCommand
271+
*/
272+
public function testInvalidJobs()
273+
{
274+
$this->expectException('phpbu\App\Exception');
275+
$file = '/tmp/foo';
276+
$pgdump = new Pgdump(PHPBU_TEST_BIN);
277+
$pgdump->dumpDatabase('phpbu')->dumpJobs(-1)->dumpTo($file);
278+
}
279+
280+
254281
/**
255282
* Tests Pgdump::getCommand
256283
*/

0 commit comments

Comments
 (0)