Skip to content

env vars not output in the PRE_COMMANDS #241

@BenRoe

Description

@BenRoe

This is my PRE_COMMANDS script.
The problem is, if i run backup inside the container i get this

backup
echo -e "[$(date)] Starting pre-backup tasks..."
[Thu Jan  8 23:36:56 CET 2026] Starting pre-backup tasks...
mkdir -p /data/database
echo -e "[$(date)] Dumping MariaDB database..."
[Thu Jan  8 23:36:56 CET 2026] Dumping MariaDB database...
mariadb-dump -h "" -u "" -p"xxxxxxxxxxxxxxxxxxxxxx" --single-transaction --lock-tables=false --skip-ssl "" > /data/database/example.sql
mariadb-dump: Got error: 2002: "Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)" when trying to connect

Any idea why user and host env vars are not printed?

...
    environment:
      ...
      RESTIC_BACKUP_ARGS: >-
        --verbose
        --tag automated
        --exclude-caches
      RESTIC_FORGET_ARGS: >-
        --keep-daily 3
        --keep-weekly 1
        --keep-monthly 0
        --prune
      RESTIC_CHECK_ARGS: --read-data-subset=10%
      BACKUP_CRON: '0 0 3 * * *'
      # Database connection for mariadb-dump
      MARIADB_HOST: 'database'
      MARIADB_USER: 'db'
      MARIADB_PASSWORD: '$SERVICE_PASSWORD_MARIADB'
      MARIADB_DATABASE: 'example'
      PRE_COMMANDS: |-
        echo -e "[$(date)] Starting pre-backup tasks..."
        mkdir -p /data/database
        echo -e "[$(date)] Dumping MariaDB database..."
        mariadb-dump -h "$MARIADB_HOST" -u "$MARIADB_USER" -p"$MARIADB_PASSWORD" --single-transaction --lock-tables=false --skip-ssl "$MARIADB_DATABASE" > /data/database/example.sql
        echo -e "[$(date)] Database dump completed: $(du -h /data/database/example.sql)"
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions