Skip to content

Commit

Permalink
allow to override the connection user per database
Browse files Browse the repository at this point in the history
  • Loading branch information
orgrim committed Jan 14, 2025
1 parent 6a52490 commit 14e39a1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## pg_back 2.6.0

* Allow to override the connection user per database

## pg_back 2.5.0

* Fix Azure URL handling
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ the configuration file).
WARNING: Azure support is not guaranted because there are no free solutions for
testing on it

When set to `b2`, files are uploaded to Backblaze B2. The `--b2-*` family of options can be used to tweak the access to
the bucket. `--b2-concurrent-connections` can be used to upload the file through parallel HTTP connections.
When set to `b2`, files are uploaded to Backblaze B2. The `--b2-*` family of
options can be used to tweak the access to the
bucket. `--b2-concurrent-connections` can be used to upload the file through
parallel HTTP connections.

The `--upload-prefix` option can be used to place the files in a remote
directory, as most cloud storage treat prefix as directories. The filename and
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ gkLoop:
knonw_perdb := []string{
"format", "parallel_backup_jobs", "compress_level", "checksum_algorithm",
"purge_older_than", "purge_min_keep", "schemas", "exclude_schemas", "tables",
"exclude_tables", "pg_dump_options", "with_blobs",
"exclude_tables", "pg_dump_options", "with_blobs", "user",
}

for _, sub := range subs {
Expand Down Expand Up @@ -745,6 +745,7 @@ func loadConfigurationFile(path string) (options, error) {
o.SumAlgo = s.Key("checksum_algorithm").MustString(opts.SumAlgo)
dbPurgeInterval = s.Key("purge_older_than").MustString(purgeInterval)
dbPurgeKeep = s.Key("purge_min_keep").MustString(purgeKeep)
o.Username = s.Key("user").MustString(opts.Username)

// Validate purge keep and time limit
keep, err := validatePurgeKeepValue(dbPurgeKeep)
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"time"
)

var version = "2.5.0"
var version = "2.6.0"
var binDir string

type dump struct {
Expand Down Expand Up @@ -111,6 +111,9 @@ type dbOpts struct {
// -B, or let pg_dump use its default. 0 means default, 1 include
// blobs, 2 exclude blobs.
WithBlobs int

// Connection user for that database
Username string
}

func main() {
Expand Down Expand Up @@ -584,6 +587,7 @@ func defaultDbOpts(opts options) *dbOpts {
PurgeInterval: opts.PurgeInterval,
PurgeKeep: opts.PurgeKeep,
PgDumpOpts: opts.PgDumpOpts,
Username: opts.Username,
}
return &dbo
}
Expand Down Expand Up @@ -682,6 +686,9 @@ func (d *dump) dump(fc chan<- sumFileJob) error {
// on the command line. For older version, it is passed using the
// environment
conninfo := d.ConnString.Set("dbname", dbname)
if d.Options.Username != "" {
conninfo = conninfo.Set("user", d.Options.Username)
}

var env []string

Expand Down
2 changes: 1 addition & 1 deletion pg_back.conf
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ upload = none
# # Per database options. Use a ini section named the same as the
# # database. These options take precedence over the global values.
# [dbname]

# user =
# format =
# parallel_backup_jobs =
# compress_level =
Expand Down

0 comments on commit 14e39a1

Please sign in to comment.