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/5375ec26a6e8453ec843e31ed116c6b35774e3a9 below:

Add --uniform-timestamp option (#146) · orgrim/pg_back@5375ec2 · GitHub

@@ -303,6 +303,12 @@ func run() (retVal error) {

303 303

}

304 304

defer db.Close()

305 305 306 +

// Generate a single datetime that will be used in all files generated by pg_back

307 +

var uniformTimestamp time.Time

308 +

if opts.UniformTimestamp {

309 +

uniformTimestamp = time.Now()

310 +

}

311 + 306 312

if !opts.DumpOnly {

307 313

if !db.superuser {

308 314

l.Infoln("connection user is not superuser, some information will not be dumped")

@@ -316,7 +322,7 @@ func run() (retVal error) {

316 322

} else {

317 323

l.Infoln("dumping globals without role passwords")

318 324

}

319 -

if err := dumpGlobals(opts.Directory, opts.Mode, opts.TimeFormat, dumpRolePasswords, conninfo, producedFiles); err != nil {

325 +

if err := dumpGlobals(opts.Directory, opts.Mode, opts.TimeFormat, dumpRolePasswords, conninfo, producedFiles, uniformTimestamp); err != nil {

320 326

return fmt.Errorf("pg_dumpall of globals failed: %w", err)

321 327

}

322 328

@@ -326,15 +332,15 @@ func run() (retVal error) {

326 332

perr *pgPrivError

327 333

)

328 334 329 -

if err := dumpSettings(opts.Directory, opts.Mode, opts.TimeFormat, db, producedFiles); err != nil {

335 +

if err := dumpSettings(opts.Directory, opts.Mode, opts.TimeFormat, db, producedFiles, uniformTimestamp); err != nil {

330 336

if errors.As(err, &verr) || errors.As(err, &perr) {

331 337

l.Warnln(err)

332 338

} else {

333 339

return fmt.Errorf("could not dump configuration parameters: %w", err)

334 340

}

335 341

}

336 342 337 -

if err := dumpConfigFiles(opts.Directory, opts.Mode, opts.TimeFormat, db, producedFiles); err != nil {

343 +

if err := dumpConfigFiles(opts.Directory, opts.Mode, opts.TimeFormat, db, producedFiles, uniformTimestamp); err != nil {

338 344

return fmt.Errorf("could not dump configuration files: %w", err)

339 345

}

340 346

}

@@ -386,6 +392,7 @@ func run() (retVal error) {

386 392

CipherPassphrase: passphrase,

387 393

CipherPublicKey: publicKey,

388 394

EncryptKeepSrc: opts.EncryptKeepSrc,

395 +

When: uniformTimestamp,

389 396

ExitCode: -1,

390 397

PgDumpVersion: pgDumpVersion,

391 398

}

@@ -613,8 +620,6 @@ func (d *dump) dump(fc chan<- sumFileJob) error {

613 620

return fmt.Errorf("could not acquire lock for %s", dbname)

614 621

}

615 622 616 -

d.When = time.Now()

617 - 618 623

var fileEnd string

619 624

switch d.Options.Format {

620 625

case 'p':

@@ -631,6 +636,10 @@ func (d *dump) dump(fc chan<- sumFileJob) error {

631 636

fileEnd = "d"

632 637

}

633 638 639 +

if d.When.IsZero() {

640 +

d.When = time.Now()

641 +

}

642 + 634 643

file := formatDumpPath(d.Directory, d.TimeFormat, fileEnd, dbname, d.When, d.Options.CompressLevel)

635 644

formatOpt := fmt.Sprintf("-F%c", d.Options.Format)

636 645

@@ -935,7 +944,7 @@ func pgToolVersion(tool string) int {

935 944

return numver

936 945

}

937 946 938 -

func dumpGlobals(dir string, mode int, timeFormat string, withRolePasswords bool, conninfo *ConnInfo, fc chan<- sumFileJob) error {

947 +

func dumpGlobals(dir string, mode int, timeFormat string, withRolePasswords bool, conninfo *ConnInfo, fc chan<- sumFileJob, uniformTimestamp time.Time) error {

939 948

command := execPath("pg_dumpall")

940 949

args := []string{"-g", "-w"}

941 950

@@ -967,7 +976,11 @@ func dumpGlobals(dir string, mode int, timeFormat string, withRolePasswords bool

967 976

args = append(args, "--no-role-passwords")

968 977

}

969 978 970 -

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

979 +

if uniformTimestamp.IsZero() {

980 +

uniformTimestamp = time.Now()

981 +

}

982 + 983 +

file := formatDumpPath(dir, timeFormat, "sql", "pg_globals", uniformTimestamp, 0)

971 984

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

972 985 973 986

if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {

@@ -1008,9 +1021,8 @@ func dumpGlobals(dir string, mode int, timeFormat string, withRolePasswords bool

1008 1021

return nil

1009 1022

}

1010 1023 1011 -

func dumpSettings(dir string, mode int, timeFormat string, db *pg, fc chan<- sumFileJob) error {

1012 - 1013 -

file := formatDumpPath(dir, timeFormat, "out", "pg_settings", time.Now(), 0)

1024 +

func dumpSettings(dir string, mode int, timeFormat string, db *pg, fc chan<- sumFileJob, uniformTimestamp time.Time) error {

1025 +

file := formatDumpPath(dir, timeFormat, "out", "pg_settings", uniformTimestamp, 0)

1014 1026 1015 1027

if err := os.MkdirAll(filepath.Dir(file), 0o700); err != nil {

1016 1028

return err

@@ -1044,9 +1056,12 @@ func dumpSettings(dir string, mode int, timeFormat string, db *pg, fc chan<- sum

1044 1056

return nil

1045 1057

}

1046 1058 1047 -

func dumpConfigFiles(dir string, mode int, timeFormat string, db *pg, fc chan<- sumFileJob) error {

1059 +

func dumpConfigFiles(dir string, mode int, timeFormat string, db *pg, fc chan<- sumFileJob, uniformTimestamp time.Time) error {

1048 1060

for _, param := range []string{"hba_file", "ident_file"} {

1049 -

file := formatDumpPath(dir, timeFormat, "out", param, time.Now(), 0)

1061 +

if uniformTimestamp.IsZero() {

1062 +

uniformTimestamp = time.Now()

1063 +

}

1064 +

file := formatDumpPath(dir, timeFormat, "out", param, uniformTimestamp, 0)

1050 1065 1051 1066

if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {

1052 1067

return err


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