Repository errors and missing snapshot after sudo restic backup

All my backups have been run without sudo except for the last one. After running restic backup with sudo for the first time, restic snapshots does not show all my snapshots anymore unless I run restic snapshots using sudo.

restic version
restic 0.18.1 compiled with go1.25.4 X:nodwarf5 on Linux/amd64

Without sudo the following error occurs and it lists all snapshots except the one run by sudo.

$ restic -r /path/to/repo/ snapshots
enter password for repository:
repository zyxwuv opened (version 2, compression level auto)
error clearing snapshot files in cache: Walk: open /home/user/.cache/restic/zyxwuv/snapshots/3b: permission denied
Load(<snapshot/abcdef>, 0, 0) failed: open /home/user/.cache/restic/zyxwuv/snapshots/3b/tmp-1390164824: permission denied
Load(<snapshot/abcdef>, 0, 0) failed: open /home/user/.cache/restic/zyxwuv/snapshots/3b/tmp-1244823494: permission denied
Ignoring “abcdefgh456”: failed to load snapshot 3b4a3c5d: open /home/user/.cache/restic/zyxwuv/snapshots/3b/tmp-1244823494: permission denied

What’s going on and how will future backups be impacted by the snapshot created by running restic backup using sudo? I’m wondering whether there will be any problems if a restic backup without sudo uses the snapshot created by sudo restic backup as a parent snapshot?

Since your backup repository is locally accessible, restic created snapshot reference with root privileges when you run with sudo, and these are not accessible without root now. That is the case for cache files at least, since even with sudo, it kept using the cache in your home folder.

What you can do to revert, is to make those files owned by your user again, with a command like:

sudo chown -R yourusername /home/yourusername/.cache/restic

afterwards it should be visible again.

This should fix the issues about cache at least, if it still has issues, I’d advise you to check your repo path and apply the same to that path if there is mixed-owned snapshot references etc.

3 Likes

This is nothing to do with restic and everything to do with unix filesystem permissions.
You’ve have had exactly the same problem if you’re run restic as user barry and then logged in as user harry to try and access to restic repo.

Thanks. If I login as root using sudo -i before running restic backup I assume I would also be unable to access the snapshot created by root but in that case the reason is that the snapshot reference would be created in .cache/restic of the root user’s directory?

Snapshots are created in the repository. Not in a cache. The latter purpose is only to speed up things.

Cache location if not explicitly specified depends on user you are using indeed. Only downside of using multiple users is your disk usage (the same cache will be created multiple times) and speed when used first time by new user.

Regardless of OS user used as long as you have access to all repo files you can access all snapshots.

In your particular case the problem is that you used regular user cache location (/home/user/.cache/restic/) with restic instance run by root (sudo) and some files there are now not fully accessible by your regular user.

The simplest solution is just delete all cache. Or change all files and dirs ownership.

Moving forward if your goal is to use sometimes regular user and sometimes root make sure that you understand your OS filesystem permissions. There are many ways to approach it. All depends on specific OS and your detailed requirements.

Or just use two different caches you specify explicitly. Not very efficient but will always work.

@kapitainsky I’m just seeing your message? How would deleting the cache help? Will it all be recreated again when accessing the repository except this time no cached files will have root permissions?

Yes. Data in cache is ephemeral. Can be deleted anytime - all or part of it.