Automatically remove unused blobs?

I have a (probably stupid) question that I wasn’t able to find an answer for: is there a way to automatically delete unused blobs? I have a gazillion of them in one repo.

Background:

Last night’s backup threw this error:

error: tree 7067c8437d833f48b672842b2d2d62eeb0792678b93b04163740f838d7f5cf1d could not be loaded; the repository could be damaged: decrypting blob
7067c8437d833f48b672842b2d2d62eeb0792678b93b04163740f838d7f5cf1d failed: ciphertext verification failed
Warning: failed to read all source data during backup

I then checked and pruned and check-unused and got a huge list of unused blobs. Just prune alone won’t do anything.

Thanks!

Which version of restic is this? Last ones are very tunable on prune so you can decrease the unused amount. Even the defaults were pretty good for me.

I’m sorry, this is version 0.12. This “max-unused” refers to unused blobs? I’ve seen previous discussions about the issue but haven’t really put much thought into the parameter. Let me check the other threads later if I find something in there!

Thanks for the mental floss!

With --max-unused you can specify how much unused space prune tolerates in your repository. If you want to delete every unused blob, you should run it with --max-unused=0.

1 Like

Okay! Starting to understand now, thank you. I got confused because --check-unused returned this long list of unused blobs and then ended with Fatal: repository contains errors which sounds like there is something wrong with the repository that needs fixing. But it’s not the unused blobs but rather the error I stated above with the tree that could not be loaded.

Is there a way to check for that? I’d guess that only --read-data detecs that, right? Do you guys think that maybe these error messages could/should be enhanced with some form of suggestion what to do to find and repair the error? Maybe I’m in an unhealthy position between user and pro where I kind of understand how restic works but don’t feel very confident trying out different things on a live repository. For me this would be really helpful.

Update: after removing all unused blobs, the --check-unused command returns no errors were found! So that seems to imply that the detection of unused blobs leads to an error message with a “fatal error”, which seems odd. Could that be the case?

1 Like

I’m a bit confused by the problems reported here. The backup command only ever accesses blobs referenced by another snapshot. And that in turn means that check/prune will not consider these blobs to be unused. So it makes little sense that prune alone should be able to fix this error. Either the problematic snapshot was removed first (and was the only user of that damaged blob), it was a damaged cached packs file which was flushed somehow, or there was some bit-flip in hardware.

check --check-unused returns an error if unused blobs are found. I wonder whether we should just remove the --check-unused flag from restic. Each time I see some usage of check --check-unused I don’t have the slightest idea what to do with the information which blobs are unused. Especially, since restic 0.12.0 it is rather uncommon to have no unused blobs.

Yes I have to admit that I am not 100% sure what happened, what I did and whether the repository is considered safe to use now. I think --check-unused is a totally valid function but returning a fatal error is somewhat misleading for those of us with only superficial knowledge about the inner workings of restic.

Something must have gone wrong during that one backup described above. But I found out the folder referenced in that faulty tree, tested copying the files from the mounted repository and was able to do it without an error. Unfortunately, it contains hours of mp4s so I am not able to tell whether the files are really okay. I just guess that if they weren’t, I’d have gotten an error during copying.

If a normal check run does not report errors then the decryption error was either a one-time error or the blob is no longer in use. So the repository should be okay.

But what does the output of check --check-unused tell you? Without knowing a lot about the inner workings of restic, the only information is basically that there are unused blobs. But prune no longer removes all unused blobs, but rather only most unused blobs. So if you run check --check-unused before and after prune, then the only change is that the number of unused blobs is lower than before.

1 Like

Thank you so much for saying my repo should be okay - it means a lot to me :heart_eyes:

And what you say about --check-unused does make sense, of course. But whether the function is there or not, it should not state that the existence of unused blobs is a fatal error.

3 Likes

I have to agree with @nicnab. After moving data between servers and cleaning up repos, I saw the same fatal error and spent half an hour trying to “fix” my repos. Perhaps make that “fatal” message a warning.

Thanks for the great work you are doing!

-Lee

What is the use case for this feature?