Restic restore command still asks for repository location despite sourcing environment variables

Hi everyone,

I’m having trouble restoring backups with Restic on Ubuntu. I have my environment variables set in a .env file, and I’m sourcing it before running the restore command, but Restic still asks me to specify the repository location.

I have a file .env.restic :


RESTIC_REPOSITORY="s3:s3.eu-central-003..."
RESTIC_PASSWORD="********"
AWS_ACCESS_KEY_ID="********"
AWS_SECRET_ACCESS_KEY="********"



source .env.restic


restic restore --target=~/Downloads --include=/backup/pictures $SNAPSHOT

but I get

Fatal: Please specify repository location (-r or --repository-file)

restic 0.16.4 compiled with go1.22.2 on linux/amd64



When I do echo $RESTIC_REPOSITORY I see my config. So I don’t understand.

I installed Restic via apt-get on Ubuntu and can’t upgrade b

eyond version 0.16.4, it says that I am on the latest version despite a 0.18.0 existing on the repo.

My questions are:

  • Is it normal that Restic does not automatically pick up the RESTIC_REPOSITORY environment variable after sourcing the .env file?

  • Am I doing something wrong with the way I’m running the restore command?

  • Should I always pass -r explicitly with the repository location, or is there a better way?

  • Could the inability to upgrade beyond 0.16.4 be related to this issue?

I think you’re running into the difference between setting and exporting an variable.
For restic (and other programs that are not your shell) to read the variables, they need to be exported, not just set. For use inside your shell, just setting them is enough.

To fix this, you could prefix export to every line in your .env.restic file, and then use your current workflow.

export RESTIC_REPOSITORY="s3:s3.eu-central-003..."
export RESTIC_PASSWORD="********"
export AWS_ACCESS_KEY_ID="********"
export AWS_SECRET_ACCESS_KEY="********"

Or you could set allexport before sourcing the file, and unset it again afterwards:

set -o allexport
source .env.restic
set +o allexport

Edit: regarding upgrading from 0.16.4, most distributions ship older restic releases in their repositories. However, as restic is a single binary, it’s easy enough to uninstall the older version provided by apt-get and install the latest version yourself.