Backup fails when container has env-var without value #4

Closed
opened 2023-11-11 22:23:05 +00:00 by JaCoB1123 · 1 comment

Hi,

first, thanks for the tool, it simpilfied my backup strategy a lot :-)

I just noticed a minor issue, when a docker-compose contains an env-variable without a value. This results in the following error:

goroutine 5 [running]:
main.parseEnv({0xc0005ae5b0, 0xc, 0xc0001cbdc8?})
     /go/src/kolaente.dev/konrad/docker-db-backup/helper.go:10 +0x10e
main.(*PostgresDumper).Dump(0xc000012688, 0x0?)
     /go/src/kolaente.dev/konrad/docker-db-backup/dump_postgres.go:22 +0xaa
main.dumpAllDatabases(0x10000?)
     /go/src/kolaente.dev/konrad/docker-db-backup/dump.go:35 +0x11a
main.main.func1()
     /go/src/kolaente.dev/konrad/docker-db-backup/main.go:30 +0x119
github.com/robfig/cron/v3.FuncJob.Run(0x0?)
     /go/pkg/mod/github.com/robfig/cron/v3@v3.0.1/cron.go:136 +0x1a
github.com/robfig/cron/v3.(*Cron).startJob.func1()
     /go/pkg/mod/github.com/robfig/cron/v3@v3.0.1/cron.go:312 +0x6a
created by github.com/robfig/cron/v3.(*Cron).startJob
     /go/pkg/mod/github.com/robfig/cron/v3@v3.0.1/cron.go:310 +0xad

It's quite obvious where the problem lies in helper.go. It only needs a length-check and a fallback to "" instead of parts[1].

The following code should work:

if len(parts) > 1 {
		env[parts[0]] = parts[1]
} else {
		env[parts[0]] = ""
}
Hi, first, thanks for the tool, it simpilfied my backup strategy a lot :-) I just noticed a minor issue, when a docker-compose contains an env-variable without a value. This results in the following error: ``` goroutine 5 [running]: main.parseEnv({0xc0005ae5b0, 0xc, 0xc0001cbdc8?}) /go/src/kolaente.dev/konrad/docker-db-backup/helper.go:10 +0x10e main.(*PostgresDumper).Dump(0xc000012688, 0x0?) /go/src/kolaente.dev/konrad/docker-db-backup/dump_postgres.go:22 +0xaa main.dumpAllDatabases(0x10000?) /go/src/kolaente.dev/konrad/docker-db-backup/dump.go:35 +0x11a main.main.func1() /go/src/kolaente.dev/konrad/docker-db-backup/main.go:30 +0x119 github.com/robfig/cron/v3.FuncJob.Run(0x0?) /go/pkg/mod/github.com/robfig/cron/v3@v3.0.1/cron.go:136 +0x1a github.com/robfig/cron/v3.(*Cron).startJob.func1() /go/pkg/mod/github.com/robfig/cron/v3@v3.0.1/cron.go:312 +0x6a created by github.com/robfig/cron/v3.(*Cron).startJob /go/pkg/mod/github.com/robfig/cron/v3@v3.0.1/cron.go:310 +0xad ``` It's quite obvious where the problem lies in helper.go. It only needs a length-check and a fallback to `""` instead of `parts[1]`. The following code should work: ``` if len(parts) > 1 { env[parts[0]] = parts[1] } else { env[parts[0]] = "" } ```
konrad added the
bug
label 2023-11-13 20:50:28 +00:00
Owner

Should be fixed in 1b17dedc47, please check with the next build.

Should be fixed in https://kolaente.dev/konrad/docker-db-backup/commit/1b17dedc478ed40e3e564118f45dcf530c73290e, please check with the next build.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: konrad/docker-db-backup#4
No description provided.