Restic --cache-dir behaviour

[restic 0.18.0 compiled with go1.24.1 on linux/amd64]

I’m fairly confused about how the --cache-dir option works.

I currently have a simple wrapper script which sets environment variable (such as RESTIC_REPOSITORY, RESTIC_PASSWORD, AWS_*, RESTIC_COMPRESSION, RESTIC_PACK_SIZE, etc)

It then ensures a directory (currently called ‘/export/restic/cache’) exists, and passes that to restic as

/usr/bin/restic --cache-dir="${CACHE_DIR}" --cleanup-cache "@"

Despite consistently setting ‘–cache-dir=’, I have cache files scattered between

  • /root/.cache/restic
  • /var/cache/restic
  • /export/restic/cache

I’ve also tried setting the following

export RESTIC_CACHE_DIR="${CACHE_DIR}"
export TMP="${CACHE_DIR}"
export TMPDIR="${CACHE_DIR}"

(originally because restic check / prune overflowed /tmp and I needed these to force it to use another directory)

It feels like restic backup as root ignores both $RESTIC_CACHE_DIR and --cache-dir and just goes to /var/cache/restic.

Other commands like restic prune ignore cache-dir entirely and write everything to /tmp or $TMP or $TMPDIR.

What is the correct way to use $CACHE_DIR for everything?

Thanks

Restic doesn’t care about whether it runs as root or not. It creates a cache directory in the folder specified by --cache-dir or the environment variable. If neither is set, then the cache xdg cache directory is used. The end result just depends on which environment variables are passed to restic.

The only command that behaves special in regards to the cache directory is the check command. prune behaves exactly like the backup command; there’s simply no code path that could cause different behavior between those commands. check defaults to creating it’s cache in the TMPDIR or /tmp as fallback. If a cache directory is set, then the cache ends up there.

tl;dr : Make sure to correctly pass RESTIC_CACHE_DIR, then the cache directory ends up there. If that still doesn’t help, then open an issue on Github and provide a full example of what doesn’t work.