Use binary store for postgres backups

This commit is contained in:
jandre 2021-02-14 10:24:45 +01:00
parent 147b70a26d
commit 8e138819a6
2 changed files with 5 additions and 2 deletions

View File

@ -46,7 +46,7 @@ func BackupPostgres(file string, hostname string, database string, username stri
return err
}
defer os.Remove("/output/.pgpass")
cmd := exec.Command(pg_dumpExec, "--clean", "--create", "--file", file, "--host", hostname, "--dbname", database, "--username", username, "--no-password")
cmd := exec.Command(pg_dumpExec, "--format=custom", "--clean", "--create", "--file", file, "--host", hostname, "--dbname", database, "--username", username, "--no-password")
cmd.Env = append(os.Environ(), "PGPASSFILE=/output/.pgpass")
output, err := cmd.CombinedOutput()
log.V(1).Info("postgres backup output", "output", string(output))

View File

@ -14,6 +14,7 @@ import (
)
var (
//psqlExec = "/usr/bin/psql"
pg_restoreExec = "/usr/bin/pg_restore"
logger logr.Logger
)
@ -32,6 +33,7 @@ func RestoreVolume(snapshotId string) error {
log.Error(err, "unable to restore volume", "output", string(output))
state = formolv1alpha1.Failure
}
log.V(1).Info("restic restore output", "output", string(output))
session.RestoreSessionUpdateTargetStatus(state)
return err
}
@ -44,7 +46,8 @@ func RestorePostgres(file string, hostname string, database string, username str
return err
}
defer os.Remove("/output/.pgpass")
cmd := exec.Command(pg_restoreExec, "--clean", "--create", "--file", file, "--host", hostname, "--dbname", database, "--username", username, "--no-password")
//cmd := exec.Command(psqlExec, "--file", file, "--host", hostname, "--dbname", database, "--username", username, "--no-password")
cmd := exec.Command(pg_restoreExec, "--format=custom", "--clean", "--host", hostname, "--dbname", database, "--username", username, "--no-password", file)
cmd.Env = append(os.Environ(), "PGPASSFILE=/output/.pgpass")
output, err := cmd.CombinedOutput()
log.V(1).Info("postgres restore output", "output", string(output))