Skip to content

Instantly share code, notes, and snippets.

@timabell
Last active June 9, 2025 13:51
Show Gist options
  • Save timabell/f70f34f8933b2abaf42789f8afdbd7d5 to your computer and use it in GitHub Desktop.
Save timabell/f70f34f8933b2abaf42789f8afdbd7d5 to your computer and use it in GitHub Desktop.
hashdeep orchestrator for data integrity checks in home folder
#!/bin/bash -v
cd "$HOME"
# in docs subdirectory so it is sync'd with syncthing
hash_file="Documents/hashdeep-checksums.txt"
mv "$hash_file" "$hash_file.bak"
backup_paths=(Music Downloads Documents Pictures Phone Dropbox repo oneplus9-home oneplus5-home)
time hashdeep -c md5 -of -r -l "${backup_paths[@]}" | tee "$hash_file"
#!/bin/bash
set -e
# usage:
# verify.sh [home folder / backup root]
# e.g.
# ./verify.sh # verify home folder
# ./verify.sh /media/tim/backup/backintime/any/tim/1/20240830-234307-766/backup/home/tim # verify backup folder
# pre-requisites:
# https://github.com/timabell/paths2html binary must be on the path
# in docs subdirectory so it is sync'd with syncthing
hash_file="Documents/hashdeep-checksums.txt"
if [ $# -lt 1 ]; then
backuproot="$HOME"
backup_paths=(Music Downloads Documents Pictures Phone Dropbox repo oneplus9-home oneplus5-home)
else
backuproot="$1"
backup_paths=.
fi
tmp_dir=$(mktemp -d -t verify-XXXXXXXXXX)
output_file="$tmp_dir/hashdeep-checksums-verification.txt"
missing_file="$tmp_dir/hashdeep-checksums-verification-missing.html"
echo "backup root: $backuproot"
echo "temp folder: $tmp_dir"
echo "output_file: $output_file"
cd "$backuproot"
# re-hash everything in verify mode to a temporary file
# array expansion syntax: https://linuxsimply.com/bash-scripting-tutorial/expansion/array-expansion/
# -o f = expert mOde, regular files only - https://linux.die.net/man/1/hashdeep
# https://explainshell.com/explain?cmd=hashdeep+-k+checksums.txt+-of+-rleavv+Folders
time hashdeep -k "$hash_file" -of -rleavv "${backup_paths[@]}" | tee "$output_file"
# Odd terminology from md5deep verify:
# - "Known file not used" means there was no match for this hash, i.e. deleted file
# - "No match" means new/modified file
grep "Known file not used" "$output_file" | sed 's/:.*//'| sort | paths2html | tee "$missing_file" && xdg-open "$missing_file"
@timabell
Copy link
Author

timabell commented Jun 9, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment