Cache Access Issues

Hi Guys,
It’s a pleasure to use restic, a simple, but powerful backup tool that follows UNIX philosophy.
So far I had almost no issues using it, apart from one related to automation and integration with systemd.
My setup consists of restic-backup.service, restic-backup.timer, restic-prune.service, restic-prune.timer.
The issue I’m experiencing is with restic-backup.service that is called by the respective timer and looks as follows:

[Unit]
Description=Restic backup service

[Service]
Type=oneshot
ExecStart=-/usr/local/bin/restic -r /media/BACKUP/ResticRepo --verbose backup --tag elementaryOS --exclude-file=/media/BACKUP/system-exclude.txt /
ExecStart=-/usr/local/bin/restic -r /media/BACKUP/ResticRepo --verbose backup --tag Data --exclude-file=/media/BACKUP/data-exclude.txt /home
ExecStart=-/usr/local/bin/restic -r /media/BACKUP/ResticRepo forget --keep-last 2 --tag manual --group-by tags
ExecStart=-/usr/local/bin/restic -r /media/BACKUP/ResticRepo forget --keep-last 4 --keep-daily 5 --keep-weekly 3 --keep-monthly 3 --keep-yearly 2 --group-by tags
EnvironmentFile=/etc/environment

When the restic-backup.service runs, it creates a backup, however, it takes longer than expected due to caching issues. Journalctl shows the following error:

unable to open cache: unable to locate cache directory: neither $XDG_CACHE_HOME nor $HOME are defined

Has anyone of you experienced this sort of problem? Do you have any idea how this could be fixed?
UPD: I use official binary: restic 0.11.0 compiled with go1.15.3 on linux/amd64

Regards,
Yura

I’ve found similar topic, but it’s not completely clear what’s the best folder location for restic cache. Official documentation states that restic looks for cache on Linux as follows:

$XDG_CACHE_HOME/restic, or ~/.cache/restic if XDG_CACHE_HOME is not set

Since systemd services run as root and home directory for root user is /root, shouldn’t it create and /root/.cache/restic folder and use it instead of returning this message?

Although, it’s not a perfect solution, but I’ve solved this by using RESTIC_CACHE_DIR environment variable.

2 Likes

Thanks! this worked also for me.

If you get the error message you mentioned before, presumably the environment variables mentioned in it aren’t set, hence restic doesn’t know where the home directory is and therefore don’t know where to create the cache.

Besides the environment variable you found and used, there’s also the --cache-dir option to restic.

1 Like