From acab514dbe53e85a4fa93fb764a972b2bd039113 Mon Sep 17 00:00:00 2001 From: Blad3Mak3r Date: Sun, 20 Nov 2022 04:23:16 +0100 Subject: [PATCH] Add customizable compression level --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index cd3c01a..a473206 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,8 @@ var ( containerCLI string allDatabases bool + compressLevel int + Version = "unknown" ) @@ -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() @@ -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() } @@ -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)) } }