Existence Detection

Just for the record: (1) and (2) has the identical certainty with such a high probability that we can state it is equal certainty.

Your general question and your use-case example is quite interesting. For a single hash, there is only one way to check if a file is equal to a stored file with known hash: compute the hash locally and compare it. However, restic chunks files and then stores the list of hashes (and the sizes of the chunks). This allows to use two different methods of testing identity of a local file with a given file in the repository:

  1. locally chunk the file, compute hashes and compare with the stored list of hashes (and maybe chunk sizes)
  2. use the already-known information about chunk sizes and compute the hashes

The first method depends on the chunker. And there can be cases (e.g. using rustic copy) where not all stored files in a restic repository are chunked by the same chunker parameters, so for this, this won’t work. (Also it is a bit slower as chunking costs some computation time).

This also goes in the direction @kapitainsky proposed. The problem with backup is that it only allows to see if the chunks exist anywhere in the repo - and it could be also that they all exist but the file still does not exist. Also you won’t know where possible file matches are located in the repository.

The second method is what is used in rustic diff (note: I’m talking about A restic client written in rust - #104 by alexweiss ) but such a diff is yet missing in restic.

Your example use case is not implemented anywhere. This also won’t work well with the second method as it would mean that for any candidate file in the repo (i.e. matching size) one would need to read the chunks fitting to the candidate and then check the hashes. I.e. a file may be read multiple times locally..

1 Like