Cache --cleanup does not alway cleanup "old" directories

The cache directory is explicitly set by the backup script to $global:CACHEDIR = “C:\Users\X\Documents\utilities\restic\cache_dir${RESTIC_SOURCE_DRIVE}”
$env:CACHEDIR = $CACHEDIR
Users\X\Documents\utilities\restic> .${RESTICEXE} version
restic 0.18.1 compiled with go1.25.1 on windows/amd64
PS C:\Users\X\Documents\utilities\restic> Write-Host “cacheeddir ${CACHEDIR}”
cacheeddir C:\Users\X\Documents\utilities\restic\cache_dir\C
PS C:\Users\X\Documents\utilities\restic> .${RESTICEXE} cache --cleanup
no old cache dirs found
When the “cache --cleanup” is run restic respond with “no old cache dir found”.
but when I manually look at the directory there are a bunch of old cache directories.
Directory: C:\Users\X\Documents\utilities\restic\cache_dir\C
Mode LastWriteTime Length Name


d---- Saturday:2022-12-24 8:45 38d972fad83859820d7906e9522674daa0e1e40807df73ef09c8c1a37a379191
AM
d---- Monday:2025-10-06 2:25 PM 5e44757d7316081b95ca744bea1da5638bea97101bc6aa9a5346d4a947dc6476
d---- Tuesday:2024-12-17 1:31 cf0c7fe40a1ff443c131d387e06edaf005fe35f6cd9a08c2f3597b3339ba995e
PM
d---- Sunday:2021-12-26 2:28 PM df3c24e1793821151b6046556d724861b21c0ca13296d376356852cdbd4b5d46
d---- Tuesday:2021-11-23 2:08 e5137ba775c0d4ecdfefb30a65f2cd27a0469814c71568d689934802475eda7c
PM
d---- Wednesday:2023-12-27 f12261a2baee5831712b210006ad6b11661a51cefaa81cf10e34c87d0c39a393
10:43 AM
As you can see most of the directories are not even from the year 2025 so why didn’t restic delete them? Does the cleanup command only look for the cache related to the current repository? If I had done a test backup with a different, i.e. “test”, repository would the cache be deleted or would it always remain until I found it manually, and deleted it manually?
Also there is a file in the cache directory called CACHEDIR.TAG what is it for, what does it do?
Since I create a completely new repository each calendar year, does that mean I can delete any cache dir which has not been updated in 2025 without any problems? The actual repository is on a external local disk. (Can all cache be deleted as long as the repository exists and restic will recreate the cache as necessary?) The cache dir is on a ssd so I would like to keep it clean.
Thank you.

How old are the files in the directory?

The files have dates which are similar or slightly earlier than the to the directory dates. So a cache_dir C:\Users\X\Documents\utilities\restic\cache_dir\C\e5137ba775c0d4ecdfefb30a65f2cd27a0469814c71568d689934802475eda7c has a date modified of 2021-11-23 and the data/ index/ and snapshots/ dirs have all modified dates the same and for the data/ the actual files 2021-11-05. The other files in the /data and /index are similar dated of 2021. I don’t think I need this and wonder why restic does not consider this “old” and delete it?

@punchcard
in case your cache directory is not set correctly, restic will falls back to other default locations and not operate in the path you think it does.

What happens if you explicitly pass the cache folder path via
restic --cache-dir "C:\Users\X\Documents\utilities\restic\cache_dir\C" cache --cleanup

EXAMPLE : when i run with your path on my computer i also get “no old cache dirs found” but the cache folder does not exist at all!

C:\Users\MyUserId>dir "C:\Users\X\Documents\utilities\restic\cache_dir\C"
The system cannot find the path specified.

C:\Users\MyUserId>restic --cache-dir "C:\Users\X\Documents\utilities\restic\cache_dir\C" cache --cleanup
no old cache dirs found

@MichaelEischer should restic not warn or give an error if the --cache-dir folder does not exist?

1 Like

Thank you for the perfect diagnosis: On the backup commands the ‘–cache-dir $cacheDir’ is explicted set but on the clean up command it was not. I guess that when I wrote the commands for a script that restic would just know somehow where the previous caches were (wrong!).

When I tried the clean up just now with the explicit cache-dir

.${RESTICEXE} --cache-dir “C:\Users\X\Documents\utilities\restic\cache_dir\C” cache --cleanup
remove 5 old cache directories

.${RESTICEXE} --cache-dir “C:\Users\X\Documents\utilities\restic\cache_dir\E” cache --cleanup
remove 3 old cache directories

Again Thank you.

Nothing really. It is supposed to indicate that a directory contains cache. And well behaving backup software should exclude it (restic would). It is some old standard (but maybe not official) you can easily google about if you are interested. If it bothers you than you can always delete it:)

Yes. Restic cache is truly ephemeral. All or any of its part can be deleted without any consequences (but restic operations speed). If something is missing restic will recreate it.