mirror of
https://kolaente.dev/konrad/docker-db-backup.git
synced 2026-01-10 02:50:08 +01:00
fix: make sure to dump everything from postgres databases
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"log"
|
||||
@@ -17,7 +16,9 @@ func NewPostgresDumper(container *types.ContainerJSON) *PostgresDumper {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *PostgresDumper) buildConnStr() string {
|
||||
func (d *PostgresDumper) Dump(c *client.Client) error {
|
||||
log.Printf("Dumping postgres database from container %s...\n", d.Container.Name)
|
||||
|
||||
env := parseEnv(d.Container.Config.Env)
|
||||
|
||||
user := "root"
|
||||
@@ -25,30 +26,5 @@ func (d *PostgresDumper) buildConnStr() string {
|
||||
user = u
|
||||
}
|
||||
|
||||
db := "postgres"
|
||||
if d, has := env["POSTGRES_DB"]; has {
|
||||
db = d
|
||||
}
|
||||
|
||||
pw := env["POSTGRES_ROOT_PASSWORD"]
|
||||
if p, has := env["POSTGRES_PASSWORD"]; has {
|
||||
pw = p
|
||||
}
|
||||
|
||||
port := "5432"
|
||||
if p, has := env["POSTGRES_PORT"]; has {
|
||||
port = p
|
||||
}
|
||||
|
||||
host := d.Container.NetworkSettings.DefaultNetworkSettings.IPAddress
|
||||
|
||||
return fmt.Sprintf("postgresql://%s:%s@%s:%s/%s", user, pw, host, port, db)
|
||||
}
|
||||
|
||||
func (d *PostgresDumper) Dump(c *client.Client) error {
|
||||
log.Printf("Dumping postgres database from container %s...\n", d.Container.Name)
|
||||
|
||||
connStr := d.buildConnStr()
|
||||
|
||||
return runAndSaveCommandInContainer(getDumpFilename(d.Container.Name), c, d.Container, "pg_dump", "--dbname", connStr)
|
||||
return runAndSaveCommandInContainer(getDumpFilename(d.Container.Name), c, d.Container, "pg_dumpall", "-U", user)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user