docker-volume-backup icon indicating copy to clipboard operation
docker-volume-backup copied to clipboard

loadConfigsFromEnvFiles does not ignore comments in file configs

Open aerz opened this issue 2 years ago • 3 comments

Describe the bug

I use files to configure multiple backups. I tried to update from v2.35.0 to the latest v2.38.0 and got the following error when loading any config file:

time=2024-02-23T15:27:18.915Z level=ERROR msg="Fatal error running command: unexpected command substitution at 1:3" error="main.(*command).runInForeground: error scheduling: main.(*command).schedule: error sourcing configuration: main.sourceConfiguration: error loading config files: main.loadConfigsFromEnvFiles: error reading config file /etc/dockervolumebackup/conf.d/test.backup.env: main.source: error expanding env: unexpected command substitution at 1:3"

Trying to figure out what is happening and a minimal way to replicate it, I found that in all my files I have comments with example variable usage, in the same way as it is done in the docs which causes the read error but was previously ignored.

Comment line is similar to:

# e.g. `backup-$HOSTNAME-%Y-%m-%dT%H-%M-%S.tar.gz`. Expansion happens before`

Or:

# `docker-volume-backup.stop-during-backup=service1`

Comments after setting a variable works:

BACKUP_CRON_EXPRESSION="15 6 */3 * *" # At 06:15 on every 3rd day-of-month

I could get it working as expected by removing all comment lines.

Expected behavior

All lines beginning with # are comments and are ignored.

aerz avatar Feb 23 '24 15:02 aerz

Hmm, this sounds plausible, but I can't reproduce it. When I extend the confd test case to use an env file like this

# This is a comment
# NOT="relevant"

NAME="$EXPANSION_VALUE"
BACKUP_CRON_EXPRESSION="*/1 * * * *"

the test case passes as expected. The same goes for the unit tests where

# This is a comment about why things are here
# FOO="${bar:-qux}"
BAR=xxx

BAZ=$QUX

is interpreted as intended. My hunch right now is that this is not caused by the hash symbols, but by the backticks which fail to expand.

m90 avatar Feb 23 '24 16:02 m90

Yes, you're right. Backticks causes the error.

This comment causes an error:

BACKUP_CRON_EXPRESSION="15 6 */3 * *" # At 06:15 on every 3rd day-of-month `foo=test`

But this comment works as expected:

BACKUP_CRON_EXPRESSION="15 6 */3 * *" # At 06:15 on every 3rd day-of-month foo=test

aerz avatar Feb 23 '24 16:02 aerz

This is fixed in v2.38.1, thanks for reporting.

m90 avatar Feb 23 '24 17:02 m90