+86
-1
lines changedFilter options
+86
-1
lines changed Original file line number Diff line number Diff line change
@@ -191,6 +191,13 @@ func main() {
191
191
}
192
192
}
193
193
194
+
if err := dumpConfigFiles(opts.Directory, opts.TimeFormat, db); err != nil {
195
+
db.Close()
196
+
l.Fatalln("could not dump configuration files:", err)
197
+
postBackupHook(opts.PostHook)
198
+
os.Exit(1)
199
+
}
200
+
194
201
databases, err := listDatabases(db, opts.WithTemplates, opts.ExcludeDbs, opts.Dbnames)
195
202
if err != nil {
196
203
l.Fatalln(err)
@@ -334,7 +341,7 @@ func main() {
334
341
}
335
342
}
336
343
337
-
for _, other := range []string{"pg_globals", "pg_settings"} {
344
+
for _, other := range []string{"pg_globals", "pg_settings", "hba_file", "ident_file"} {
338
345
limit := now.Add(defDbOpts.PurgeInterval)
339
346
if err := purgeDumps(opts.Directory, other, defDbOpts.PurgeKeep, limit); err != nil {
340
347
exitCode = 1
@@ -607,3 +614,27 @@ func dumpSettings(dir string, timeFormat string, db *pg) error {
607
614
608
615
return nil
609
616
}
617
+
618
+
func dumpConfigFiles(dir string, timeFormat string, db *pg) error {
619
+
for _, param := range []string{"hba_file", "ident_file"} {
620
+
file := formatDumpPath(dir, timeFormat, "out", param, time.Now())
621
+
622
+
if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
623
+
return err
624
+
}
625
+
626
+
s, err := extractFileFromSettings(db, param)
627
+
if err != nil {
628
+
return err
629
+
}
630
+
631
+
// Use a Buffer to avoid creating an empty file
632
+
if len(s) > 0 {
633
+
l.Verbosef("writing contents of '%s' to: %s", param, file)
634
+
if err := ioutil.WriteFile(file, []byte(s), 0644); err != nil {
635
+
return err
636
+
}
637
+
}
638
+
}
639
+
return nil
640
+
}
Original file line number Diff line number Diff line change
@@ -506,6 +506,41 @@ func showSettings(db *pg) (string, error) {
506
506
}
507
507
}
508
508
509
+
func extractFileFromSettings(db *pg, name string) (string, error) {
510
+
query := "SELECT setting, pg_read_file(setting, 0, (pg_stat_file(setting)).size) FROM pg_settings WHERE name = $1"
511
+
512
+
l.Verboseln("executing SQL query:", query)
513
+
rows, err := db.conn.Query(query, name)
514
+
if err != nil {
515
+
return "", fmt.Errorf("could not query file contents from settings: %s", err)
516
+
}
517
+
defer rows.Close()
518
+
519
+
var result string
520
+
521
+
for rows.Next() {
522
+
var (
523
+
path string
524
+
contents string
525
+
)
526
+
527
+
err := rows.Scan(&path, &contents)
528
+
if err != nil {
529
+
l.Errorln(err)
530
+
continue
531
+
}
532
+
533
+
result = fmt.Sprintf("# path: %s\n%s\n", path, contents)
534
+
}
535
+
536
+
err = rows.Err()
537
+
if err != nil {
538
+
return "", fmt.Errorf("could not retrive rows: %s", err)
539
+
}
540
+
541
+
return result, nil
542
+
}
543
+
509
544
type pgReplicaHasLocks struct{}
510
545
511
546
func (*pgReplicaHasLocks) Error() string {
Original file line number Diff line number Diff line change
@@ -292,5 +292,24 @@ func TestDumpCreateDBAndACL(t *testing.T) {
292
292
}
293
293
}
294
294
295
+
func TestExtractFileFromSettings(t *testing.T) {
296
+
needPgConn(t)
297
+
298
+
got, err := extractFileFromSettings(testdb, "hba_file")
299
+
if err != nil {
300
+
t.Errorf("expected non nil error, got %q", err)
301
+
}
302
+
303
+
if got == "" {
304
+
t.Errorf("expected some data, got nothing")
305
+
} else {
306
+
c := strings.Split(got, "\n")
307
+
re := regexp.MustCompile(`^# path: \S+`)
308
+
if !re.MatchString(c[0]) {
309
+
t.Errorf("excepted string matching \"^# path: \\S+\", got %s", c[0])
310
+
}
311
+
}
312
+
}
313
+
295
314
// Testing replication management fonctions needs a more complex setup
296
315
// so we skip it.
You can’t perform that action at this time.
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