![Go Reference](https://camo.githubusercontent.com/b5373c22274cc3aaa1119593f0483fcba25eb4a7ad8936b99013ac59a7c2da15/68747470733a2f2f706b672e676f2e6465762f62616467652f6769746875622e636f6d2f686162782f70672d636f6d6d616e64732e737667)
go get -t github.com/habx/pg-commands
dump, _ := pg.NewDump(&pg.Postgres{
Host: "localhost",
Port: 5432,
DB: "dev_example",
Username: "example",
Password: "example",
})
dumpExec := dump.Exec(pg.ExecOptions{StreamPrint: false})
if dumpExec.Error != nil {
fmt.Println(dumpExec.Error.Err)
fmt.Println(dumpExec.Output)
} else {
fmt.Println("Dump success")
fmt.Println(dumpExec.Output)
}
restore, _ := pg.NewRestore(&pg.Postgres{
Host: "localhost",
Port: 5432,
DB: "dev_example",
Username: "example",
Password: "example",
})
restoreExec := restore.Exec(dumpExec.File, pg.ExecOptions{StreamPrint: false})
if restoreExec.Error != nil {
fmt.Println(restoreExec.Error.Err)
fmt.Println(restoreExec.Output)
} else {
fmt.Println("Restore success")
fmt.Println(restoreExec.Output)
}
$ cd examples
$ docker-compose up -d
$ cd ..
$ POSTGRES_USER=example POSTGRES_PASSWORD=example POSTGRES_DB=postgres go run tests/fixtures/scripts/init-database/init-database.go
$ go run main.go
Dump success
Restore success