Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional feature for pg_dump.. #52

Open
PGPAWAN opened this issue Sep 27, 2023 · 1 comment
Open

Additional feature for pg_dump.. #52

PGPAWAN opened this issue Sep 27, 2023 · 1 comment

Comments

@PGPAWAN
Copy link

PGPAWAN commented Sep 27, 2023

What if we need to take only schema backup without data? (pg_dump -s)

What if we need to take a specific schema backup with database?(pg_dump -n

@clementlecorre
Copy link
Member

Hey @PGPAWAN

You can override your options here: dump.Options = []string{"-s"} or dump.Options = []string{"-n"}

package main

import (
	"fmt"

	"os"

	pg "github.com/habx/pg-commands"
)

func main() {
	dump, err := pg.NewDump(&pg.Postgres{
		Host:     "localhost",
		Port:     5432,
		DB:       "dev_example",
		Username: "example",
		Password: "example",
	})
	if err != nil {
		panic(err)
	}

	dump.EnableVerbose()
	dump.ResetOptions()
	// plain text fmt
	format := "p"
	dump.Format = &format
	dump.SetFileName("test.sql")
	dump.SetPath("examples/")
	// --- SETUP YOUR OPTIONS HERE ---
	dump.Options = []string{"-s"}
	// --- --- --- --- --- --- --- ---

	dumpExec := dump.Exec(pg.ExecOptions{StreamPrint: true, StreamDestination: os.Stdout})
	if dumpExec.Error != nil {
		fmt.Println(dumpExec.Error.Err)
		fmt.Println(dumpExec.Output)
	} else {
		fmt.Println("Dump success")
		fmt.Println(dumpExec.Output)
	}
	fmt.Println("full command executed: pg_dump", dumpExec.FullCommand)
}

logs:
full command executed: pg_dump -s --dbname=dev_example --host=localhost --port=5432 --username=example -Fp -v -fexamples/test.sql

Does this solve your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants