diff --git a/cmd/restic/cmd_fsck.go b/cmd/restic/cmd_fsck.go index d3b48271d..0cd52d879 100644 --- a/cmd/restic/cmd_fsck.go +++ b/cmd/restic/cmd_fsck.go @@ -32,10 +32,11 @@ func init() { } func fsckFile(opts CmdFsck, s restic.Server, m *restic.Map, IDs []backend.ID) (uint64, error) { + debug.Log("restic.fsckFile", "checking file %v", IDs) var bytes uint64 for _, id := range IDs { - debug.Log("restic.fsck", "checking data blob %v\n", id) + debug.Log("restic.fsck", " checking data blob %v\n", id) // test if blob is in map blob, err := m.FindID(id) @@ -44,6 +45,7 @@ func fsckFile(opts CmdFsck, s restic.Server, m *restic.Map, IDs []backend.ID) (u } bytes += blob.Size + debug.Log("restic.fsck", " data blob found: %v\n", blob) if opts.CheckData { // load content @@ -73,7 +75,7 @@ func fsckFile(opts CmdFsck, s restic.Server, m *restic.Map, IDs []backend.ID) (u } func fsckTree(opts CmdFsck, s restic.Server, blob restic.Blob) error { - debug.Log("restic.fsck", "checking tree %v\n", blob.ID) + debug.Log("restic.fsckTree", "checking tree %v", blob) tree, err := restic.LoadTree(s, blob.Storage) if err != nil { @@ -102,10 +104,12 @@ func fsckTree(opts CmdFsck, s restic.Server, blob restic.Blob) error { switch node.Type { case "file": if node.Content == nil { + debug.Log("restic.fsckTree", "file node %q of tree %v has no content: %v", node.Name, blob.ID, node) return fmt.Errorf("file node %q of tree %v has no content: %v", node.Name, blob.ID, node) } if node.Content == nil && node.Error == "" { + debug.Log("restic.fsckTree", "file node %q of tree %v has no content", node.Name, blob.ID) return fmt.Errorf("file node %q of tree %v has no content", node.Name, blob.ID) } @@ -114,12 +118,14 @@ func fsckTree(opts CmdFsck, s restic.Server, blob restic.Blob) error { seenIDs.Insert(id) } + debug.Log("restic.fsckTree", "check file %v (%v)", node.Name, blob.ID.Str()) bytes, err := fsckFile(opts, s, tree.Map, node.Content) if err != nil { return err } if bytes != node.Size { + debug.Log("restic.fsckTree", "file node %q of tree %v has size %d, but only %d bytes could be found", node.Name, blob, node.Size, bytes) return fmt.Errorf("file node %q of tree %v has size %d, but only %d bytes could be found", node.Name, blob, node.Size, bytes) } case "dir": diff --git a/node_linux.go b/node_linux.go index a430fa885..1c7552188 100644 --- a/node_linux.go +++ b/node_linux.go @@ -82,7 +82,7 @@ func (node *Node) isNewer(path string, fi os.FileInfo) bool { tpe := nodeTypeFromFileInfo(path, fi) if node.Name != fi.Name() || node.Type != tpe { debug.Log("node.isNewer", "node %v is newer: name or type changed", path) - return false + return true } // collect extended stat @@ -97,8 +97,8 @@ func (node *Node) isNewer(path string, fi os.FileInfo) bool { node.ChangeTime != changeTime || node.Inode != inode || node.Size != size { - debug.Log("node.isNewer", "node %v is newer: timestamp or inode changed", path) - return false + debug.Log("node.isNewer", "node %v is newer: timestamp, size or inode changed", path) + return true } // otherwise the node is assumed to have the same content diff --git a/testsuite/test-backup-incremental.sh b/testsuite/test-backup-incremental.sh new file mode 100755 index 000000000..0a9ca3ec5 --- /dev/null +++ b/testsuite/test-backup-incremental.sh @@ -0,0 +1,28 @@ +set -e + +prepare +run restic init + +# create testfile +echo "testfile" > ${BASE}/fake-data/file + +# run first backup +run restic backup "${BASE}/fake-data" + +# remember snapshot id +SNAPSHOT=$(run restic list snapshots) + +# add data to testfile +date >> ${BASE}/fake-data/file + +# run backup again +run restic backup "${BASE}/fake-data" + +# add data to testfile +date >> ${BASE}/fake-data/file + +# run incremental backup +run restic backup -p "$SNAPSHOT" "${BASE}/fake-data" + +run restic fsck -o --check-data +cleanup diff --git a/testsuite/test-backup.sh b/testsuite/test-backup.sh index 848ff48a2..f5500d5c2 100755 --- a/testsuite/test-backup.sh +++ b/testsuite/test-backup.sh @@ -7,7 +7,7 @@ run restic restore "$(basename "$RESTIC_REPOSITORY"/snapshots/*)" "${BASE}/fake- dirdiff "${BASE}/fake-data" "${BASE}/fake-data-restore/fake-data" SNAPSHOT=$(run restic list snapshots) -run restic backup "${BASE}/fake-data" $SNAPSHOT +run restic backup -p "$SNAPSHOT" "${BASE}/fake-data" run restic restore "$(basename "$RESTIC_REPOSITORY"/snapshots/*)" "${BASE}/fake-data-restore-incremental" dirdiff "${BASE}/fake-data" "${BASE}/fake-data-restore-incremental/fake-data"