Add postgres dumper
This commit is contained in:
parent
7a24e57e09
commit
e85384d0da
|
@ -1,3 +1,4 @@
|
||||||
.idea/
|
.idea/
|
||||||
docker-db-backup
|
docker-db-backup
|
||||||
*.sql
|
*.sql
|
||||||
|
./backups
|
||||||
|
|
|
@ -44,7 +44,7 @@ func init() {
|
||||||
func updateFullBackupPath() {
|
func updateFullBackupPath() {
|
||||||
dumpTime = time.Now()
|
dumpTime = time.Now()
|
||||||
config.fullCurrentBackupPath = config.Folder + dumpTime.Format("02-01-2006_15-04-05") + "/"
|
config.fullCurrentBackupPath = config.Folder + dumpTime.Format("02-01-2006_15-04-05") + "/"
|
||||||
err := os.MkdirAll(config.fullCurrentBackupPath, 0644)
|
err := os.MkdirAll(config.fullCurrentBackupPath, 0744)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not create backup folder: %s\n", err)
|
log.Fatalf("Could not create backup folder: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/docker/docker/api/types"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
)
|
||||||
|
|
||||||
type PostgresDumper struct {
|
type PostgresDumper struct {
|
||||||
Container *types.ContainerJSON
|
Container *types.ContainerJSON
|
||||||
|
@ -12,6 +15,35 @@ func NewPostgresDumper(container *types.ContainerJSON) *PostgresDumper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PostgresDumper) Dump() error {
|
func (d *PostgresDumper) Dump() error {
|
||||||
panic("implement me")
|
fmt.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
|
||||||
|
}
|
||||||
|
|
||||||
|
db := ""
|
||||||
|
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
|
||||||
|
|
||||||
|
connStr := fmt.Sprintf("postgresql://%s:%s@%s:%s/%s", user, pw, host, port, db)
|
||||||
|
|
||||||
|
// TODO: Check postgres image version and use the correct pg_dump
|
||||||
|
|
||||||
|
return runAndSaveCommand(getDumpFilename(d.Container.Name), "pg_dump", "--dbname", connStr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue