-
-
Save nlitsme/dc309d3ba72a3de24da4f6c5bcce136e to your computer and use it in GitHub Desktop.
Search timemachine backups and apfs snapshots for a specific file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Script which scans all your mounted timemachine volumes, and apfs snapshots for a specific file. | |
# | |
# Willem Hengeveld <[email protected]> | |
# | |
if [[ $(id -u) -ne 0 ]]; then | |
sudo $0 "$@" | |
exit $? | |
fi | |
tmutil listlocalsnapshots / | while read sn; do | |
mkdir "/Volumes/$sn" 2>/dev/null | |
mount_apfs -o ro -s "$sn" / "/Volumes/$sn" 2>/dev/null | |
done | |
bkdir= | |
while [[ -n "$1" ]]; do | |
cd "$(dirname "$1")" | |
realpath=$(pwd -P) | |
case "$realpath" in | |
/Volumes/*) | |
realpath="${realpath:9}" | |
;; | |
*) | |
realpath="$realpath" | |
;; | |
esac | |
# the perl code filters out duplicates from timemachine volume, based on inode number. | |
# list timemachine backups. | |
ls -ild /Volumes/*/Backups.backupdb/*/20*/*"$realpath/$(basename "$1")" | perl -nle 'if (/^\s*(\d+)\s(.*)/ && !$x{$1}++) { print $2; }' | |
# list local snapshots. | |
ls -ild /Volumes/com.apple.TimeMachine.20*"$realpath/$(basename "$1")" | perl -nle 'if (/^\s*(\d+)\s(.*)/ && !$x{$1}++) { print $2; }' | |
shift | |
done | |
for sd in /Volumes/com.apple.TimeMachine.20*; do | |
umount -f "$sd" 2>/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment