Skip to content

Commit

Permalink
Merge pull request #4526 from dnnr/detect-bitrot-in-diff
Browse files Browse the repository at this point in the history
Add bitrot detection to "diff" command
  • Loading branch information
MichaelEischer committed Jan 6, 2024
2 parents 634e2a4 + 4f6b1bb commit b2b7669
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions changelog/unreleased/pull-4526
@@ -0,0 +1,11 @@
Enhancement: Add bitrot detection to `diff` command

The output of the `diff` command now includes the modifier `?` for files
to indicate bitrot in backed up files. It will appear whenever there is a
difference in content while the metadata is exactly the same. Since files with
unchanged metadata are normally not read again when creating a backup, the
detection is only effective if the right-hand side of the diff has been created
with "backup --force".

https://github.com/restic/restic/issues/805
https://github.com/restic/restic/pull/4526
14 changes: 14 additions & 0 deletions cmd/restic/cmd_diff.go
Expand Up @@ -27,6 +27,10 @@ directory:
* U The metadata (access mode, timestamps, ...) for the item was updated
* M The file's content was modified
* T The type was changed, e.g. a file was made a symlink
* ? Bitrot detected: The file's content has changed but all metadata is the same
Metadata comparison will likely not work if a backup was created using the
'--ignore-inode' or '--ignore-ctime' option.
To only compare files in specific subfolders, you can use the
"<snapshotID>:<subfolder>" syntax, where "subfolder" is a path within the
Expand Down Expand Up @@ -272,6 +276,16 @@ func (c *Comparer) diffTree(ctx context.Context, stats *DiffStatsContainer, pref
!reflect.DeepEqual(node1.Content, node2.Content) {
mod += "M"
stats.ChangedFiles++

node1NilContent := *node1
node2NilContent := *node2
node1NilContent.Content = nil
node2NilContent.Content = nil
// the bitrot detection may not work if `backup --ignore-inode` or `--ignore-ctime` were used
if node1NilContent.Equals(node2NilContent) {
// probable bitrot detected
mod += "?"
}
} else if c.opts.ShowMetadata && !node1.Equals(*node2) {
mod += "U"
}
Expand Down
3 changes: 2 additions & 1 deletion doc/075_scripting.rst
Expand Up @@ -201,7 +201,8 @@ change
+------------------+--------------------------------------------------------------+
| ``modifier`` | Type of change, a concatenation of the following characters: |
| | "+" = added, "-" = removed, "T" = entry type changed, |
| | "M" = file content changed, "U" = metadata changed |
| | "M" = file content changed, "U" = metadata changed, |
| | "?" = bitrot detected |
+------------------+--------------------------------------------------------------+

statistics
Expand Down

0 comments on commit b2b7669

Please sign in to comment.