@@ -191,6 +191,13 @@ func main() {
191191 }
192192 }
193193
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+
194201 databases , err := listDatabases (db , opts .WithTemplates , opts .ExcludeDbs , opts .Dbnames )
195202 if err != nil {
196203 l .Fatalln (err )
@@ -334,7 +341,7 @@ func main() {
334341 }
335342 }
336343
337- for _ , other := range []string {"pg_globals" , "pg_settings" } {
344+ for _ , other := range []string {"pg_globals" , "pg_settings" , "hba_file" , "ident_file" } {
338345 limit := now .Add (defDbOpts .PurgeInterval )
339346 if err := purgeDumps (opts .Directory , other , defDbOpts .PurgeKeep , limit ); err != nil {
340347 exitCode = 1
@@ -607,3 +614,27 @@ func dumpSettings(dir string, timeFormat string, db *pg) error {
607614
608615 return nil
609616}
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+ }
0 commit comments