ngosang / restic-exporter

Prometheus exporter for the Restic backup system
MIT License
79 stars 17 forks source link

Environment variable "RESTIC_REPO_PASSWORD" is not read by restic-exporter.py #22

Closed shiftZZnet closed 8 months ago

shiftZZnet commented 10 months ago

Dear contributors,

you are mentioning the following in the configuration section for restic-exporter:

Configuration
[...]
All configuration is done with environment variables:
RESTIC_REPO_URL: Restic repository URL. All backends are supported
[...]
RESTIC_REPO_PASSWORD: Restic repository password in plain text. This is only required if RESTIC_REPO_PASSWORD_FILE is not defined.

I want to reuse my restic configuration file so I wrote a startup wrapper for restic-exporter sourcing the configuration and setting the value for RESTIC_REPO_PASSWORD like this:

# take all environment entries from restic backup
. /etc/dot-backup/dot-backup.conf
# set variables according to restic backup
export RESTIC_REPO_URL=${RESTIC_REPOSITORY}
export RESTIC_REPO_PASSWORD=${RESTIC_PASSWORD}
export NO_STATS=true
export NO_CHECK=true
export REFRESH_INTERVAL=3600

Unfortunately restic-exporter does not startup when executing the python file:

root@${hostname}:/usr/local/bin# restic-exporter
2023-11-07 12:21:27 INFO     Starting Restic Prometheus Exporter
2023-11-07 12:21:27 INFO     It could take a while if the repository is remote
2023-11-07 12:21:27 ERROR    The environment variable RESTIC_REPO_PASSWORD_FILE is mandatory

The code block in restic-exporter.py looks like this:

 try:
        restic_repo_url = os.environ["RESTIC_REPO_URL"]
    except Exception:
        logging.error("The environment variable RESTIC_REPO_URL is mandatory")
        sys.exit(1)

Could anybody fix this issue perhaps? I don't want to use a separate password file for this.

Many thanks in advance! Joachim.

ngosang commented 8 months ago

Fixed in 1.5.0 / 4efcaba7c5aa4969b71d7ca6cf77c072d0587329

shiftZZnet commented 7 months ago

Dear @ngosang,

thanks a lot for the try to fix the issue, but the usage of RESTIC_REPO_PASSWORD_FILE is still mandatory.

My goal/idea was: If I already have an environment file containing the following entries:

export RESTIC_PASSWORD=<password>
export RESTIC_REPOSITORY=<repository>

I exptected that restic-exporter is using these environment values. But you are still referring to a password file in restic-exporter.py like this:

  restic_repo_password_file = os.environ.get("RESTIC_PASSWORD_FILE")
    if restic_repo_password_file is None:
        restic_repo_password_file = os.environ.get("RESTIC_REPO_PASSWORD_FILE")
        if restic_repo_password_file is not None:
            logging.warning(
                "The environment variable RESTIC_REPO_PASSWORD_FILE is deprecated, "
                "please use RESTIC_PASSWORD_FILE instead."
            )
    if restic_repo_password_file is None:
        logging.error("The environment variable RESTIC_PASSWORD_FILE is mandatory")
        sys.exit(1)

You are not using the variable RESTIC_PASSWORD in your python script.

The reason for it is that I don't want to have a second place, i.e an additonal RESTIC_PASSWORD_FILE. I already have a configuration file for my backup and restic-exporter.py should be able either to read from a password file or read the password from the environment.

I hope it's clearer now.

Thanks in advanve for reading and have a nice day!