Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ postgres := &barkup.Postgres{

// Not necessary if the program runs as an authorized pg user/role
Username: "XXXXXXXX",
Password: "XXXXX",

// Any extra pg_dump options
Options: []string{"--no-owner"},
Expand All @@ -142,7 +143,9 @@ if (result.Error != nil) { panic(result.Error) }

**Connection credentials**

You have two options for allowing barkup to connect to your DB.
You have three options for allowing barkup to connect to your DB.

Use the Password struct field to set password as the PGPASSWORD enviroment variable.

Add a [`~/.pgpass`](http://www.postgresql.org/docs/9.3/static/libpq-pgpass.html) for account that will run the backup program.

Expand Down
16 changes: 15 additions & 1 deletion postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package barkup

import (
"fmt"
"os"
"os/exec"
"time"
)
Expand All @@ -21,6 +22,8 @@ type Postgres struct {
DB string
// Connection Username
Username string
// Connecion Password
Password string
// Extra pg_dump options
// e.g []string{"--inserts"}
Options []string
Expand All @@ -31,10 +34,21 @@ func (x Postgres) Export() *ExportResult {
result := &ExportResult{MIME: "application/x-tar"}
result.Path = fmt.Sprintf(`bu_%v_%v.sql.tar.gz`, x.DB, time.Now().Unix())
options := append(x.dumpOptions(), "-Fc", fmt.Sprintf(`-f%v`, result.Path))
out, err := exec.Command(PGDumpCmd, options...).Output()

// Adds a password varible to exec enviroment.
// Can be used instead of ~/.pgpass
args := os.Environ()
if x.Password != "" {
args = append(args, "PGPASSWORD="+x.Password)
}

cmd := exec.Command(PGDumpCmd, options...)
cmd.Args = args
out, err := cmd.Output()
if err != nil {
result.Error = makeErr(err, string(out))
}

return result
}

Expand Down