A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/orgrim/pg_back/commit/2d082e925b2d13ec28b1f9ec14a714dc397374ba below:

check and adapt to the version of pg_dump and pg_dumpall · orgrim/pg_back@2d082e9 · GitHub

@@ -63,6 +63,9 @@ type dump struct {

63 63

// Result

64 64

When time.Time

65 65

ExitCode int

66 + 67 +

// Version of pg_dump

68 +

PgDumpVersion int

66 69

}

67 70 68 71

type dbOpts struct {

@@ -150,6 +153,8 @@ func main() {

150 153

binDir = opts.BinDirectory

151 154

}

152 155 156 +

pgDumpVersion := pgToolVersion("pg_dump")

157 + 153 158

// Parse the connection information

154 159

l.Verboseln("processing input connection parameters")

155 160

conninfo, err := prepareConnInfo(opts.Host, opts.Port, opts.Username, opts.ConnDb)

@@ -268,12 +273,13 @@ func main() {

268 273

}

269 274 270 275

d := &dump{

271 -

Database: dbname,

272 -

Options: o,

273 -

Directory: opts.Directory,

274 -

TimeFormat: opts.TimeFormat,

275 -

ConnString: conninfo,

276 -

ExitCode: -1,

276 +

Database: dbname,

277 +

Options: o,

278 +

Directory: opts.Directory,

279 +

TimeFormat: opts.TimeFormat,

280 +

ConnString: conninfo,

281 +

ExitCode: -1,

282 +

PgDumpVersion: pgDumpVersion,

277 283

}

278 284 279 285

l.Verbosef("sending dump job for database %s to worker pool", dbname)

@@ -434,6 +440,10 @@ func (d *dump) dump() error {

434 440

case 't':

435 441

fileEnd = "tar"

436 442

case 'd':

443 +

if d.PgDumpVersion < 90100 {

444 +

return fmt.Errorf("provided pg_dump version does not support directory format")

445 +

}

446 + 437 447

fileEnd = "d"

438 448

}

439 449

@@ -444,13 +454,17 @@ func (d *dump) dump() error {

444 454

args := []string{formatOpt, "-f", file, "-w"}

445 455 446 456

if fileEnd == "d" && d.Options.Jobs > 1 {

447 -

args = append(args, "-j", fmt.Sprintf("%d", d.Options.Jobs))

457 +

if d.PgDumpVersion < 90300 {

458 +

l.Warnln("provided pg_dump version does not support parallel jobs, ignoring option")

459 +

} else {

460 +

args = append(args, "-j", fmt.Sprintf("%d", d.Options.Jobs))

461 +

}

448 462

}

449 463 450 464

// It is recommended to use --create with the plain format

451 465

// from PostgreSQL 11 to get the ACL and configuration of the

452 466

// database

453 -

if pgToolVersion("pg_dump") >= 110000 && fileEnd == "sql" {

467 +

if d.PgDumpVersion >= 110000 && fileEnd == "sql" {

454 468

args = append(args, "--create")

455 469

}

456 470

@@ -472,7 +486,11 @@ func (d *dump) dump() error {

472 486

case 1: // with blobs

473 487

args = append(args, "-b")

474 488

case 2: // without blobs

475 -

args = append(args, "-B")

489 +

if d.PgDumpVersion < 100000 {

490 +

l.Warnln("provided pg_dump version does not support excluding blobs, ignoring option")

491 +

} else {

492 +

args = append(args, "-B")

493 +

}

476 494

}

477 495 478 496

// Add compression level option only if not dumping in the plain format

@@ -489,11 +507,22 @@ func (d *dump) dump() error {

489 507

}

490 508 491 509

// Connection option are passed as a connstring even if we add options

492 -

// on the command line

510 +

// on the command line. For older version, it is passed using the

511 +

// environment

493 512

conninfo := d.ConnString.Set("dbname", dbname)

494 -

args = append(args, "-d", conninfo.String())

513 + 514 +

var env []string

515 + 516 +

if d.PgDumpVersion < 90300 {

517 +

args = append(args, dbname)

518 +

env = os.Environ()

519 +

env = append(env, d.ConnString.MakeEnv()...)

520 +

} else {

521 +

args = append(args, "-d", conninfo.String())

522 +

}

495 523 496 524

pgDumpCmd := exec.Command(command, args...)

525 +

pgDumpCmd.Env = env

497 526

l.Verboseln("running:", pgDumpCmd)

498 527

stdoutStderr, err := pgDumpCmd.CombinedOutput()

499 528

if err != nil {

@@ -615,7 +644,17 @@ func dumpGlobals(dir string, timeFormat string, conninfo *ConnInfo, fc chan<- st

615 644

args = append(args, "-l", dbname)

616 645

}

617 646 618 -

args = append(args, "-d", conninfo.String())

647 +

// With older version of PostgreSQL not supporting connection strings

648 +

// on their -d option, use the environment to pass the connection

649 +

// information

650 +

var env []string

651 + 652 +

if pgToolVersion("pg_dumpall") < 90300 {

653 +

env = os.Environ()

654 +

env = append(env, conninfo.MakeEnv()...)

655 +

} else {

656 +

args = append(args, "-d", conninfo.String())

657 +

}

619 658 620 659

file := formatDumpPath(dir, timeFormat, "sql", "pg_globals", time.Now())

621 660

args = append(args, "-f", file)

@@ -625,6 +664,7 @@ func dumpGlobals(dir string, timeFormat string, conninfo *ConnInfo, fc chan<- st

625 664

}

626 665 627 666

pgDumpallCmd := exec.Command(command, args...)

667 +

pgDumpallCmd.Env = env

628 668

l.Verboseln("running:", pgDumpallCmd)

629 669

stdoutStderr, err := pgDumpallCmd.CombinedOutput()

630 670

if err != nil {


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4