Skip to content

Commit

Permalink
Add customizable compression level
Browse files Browse the repository at this point in the history
  • Loading branch information
Blad3Mak3r committed Nov 20, 2022
1 parent 0244d8c commit acab514
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var (
containerCLI string
allDatabases bool

compressLevel int

Version = "unknown"
)

Expand Down Expand Up @@ -123,6 +125,7 @@ func init() {

flag.StringVar(&containerCLI, "cli", "docker", "Determine runtime command like docker (default), nerdctl, podman... must be a docker compatible CLI.")
flag.StringVar(&containerId, "cid", "", "Specific the ID (or name) of the container in which the instance of the database is running, this will avoid the requirement that the command is executed by the postgre user.")
flag.IntVar(&compressLevel, "compress", 5, "The compress level (default to 5)")

flag.Parse()

Expand All @@ -132,6 +135,10 @@ func init() {
os.Exit(0)
}

if compressLevel < 0 && compressLevel > 9 {
log.Fatalln("the compression level must be between 0 and 9 (both inclusive)")
}

config.init()
}

Expand Down Expand Up @@ -167,7 +174,7 @@ func buildCommand(destination string) *exec.Cmd {
} else if allDatabases {
return exec.Command(containerCLI, "exec", containerId, baseCommand, fmt.Sprintf("--dbname=postgresql://%s:%s@%s:%d", config.Database.Username, config.Database.Password, config.Database.Host, config.Database.Port))
} else {
return exec.Command(containerCLI, "exec", containerId, baseCommand, "-Z5", "-Fc", fmt.Sprintf("--dbname=postgresql://%s:%s@%s:%d/%s", config.Database.Username, config.Database.Password, config.Database.Host, config.Database.Port, config.Database.Name))
return exec.Command(containerCLI, "exec", containerId, baseCommand, fmt.Sprintf("-Z%d", compressLevel), "-Fc", fmt.Sprintf("--dbname=postgresql://%s:%s@%s:%d/%s", config.Database.Username, config.Database.Password, config.Database.Host, config.Database.Port, config.Database.Name))
}
}

Expand Down

0 comments on commit acab514

Please sign in to comment.