mirror of
https://github.com/kolaente/docker-db-backup.git
synced 2026-03-25 05:53:48 +01:00
Also updates all affected new types. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: kolaente <k@knt.li>
32 lines
644 B
Go
32 lines
644 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
type PostgresDumper struct {
|
|
Container *container.InspectResponse
|
|
}
|
|
|
|
func NewPostgresDumper(ctr *container.InspectResponse) *PostgresDumper {
|
|
return &PostgresDumper{
|
|
Container: ctr,
|
|
}
|
|
}
|
|
|
|
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"
|
|
if u, has := env["POSTGRES_USER"]; has {
|
|
user = u
|
|
}
|
|
|
|
return runAndSaveCommandInContainer(c, d.Container, "pg_dumpall", "-U", user)
|
|
}
|