0

If I have a file or directory path, how can I list all Time Machine backups of that path?

  • You realize that Time Machine uses hard links - so each interval where that file was present will have a backup of that path? Look at the hard link counts and you can see how many instances of that version of the file are on the volume. – bmike Mar 17 '16 at 18:31
  • @bmike: That's true. I wasn't really concerned with duplicate entries though -- just interested in a list of dates that have backups, so I can easily restore one. – JW. Mar 21 '16 at 21:07
2

Here's my attempt:

#!/bin/bash
# list Time Machine backups of a file starting with most recent

if [ "$#" -ne 1 ]; then
    echo "Usage: list_backups.sh filename"
    exit
fi

filename=`realpath "$1"`

# find root volume path
for vol in /Volumes/*; do 
    if [ "$(readlink "$vol")" = / ]; then 
        root_vol=$vol
    fi
done 

# prepend it to input path if necessary
if [[ "$filename" != /Volumes* ]]; then
    filename="$root_vol$filename"
fi

# remove /Volumes from input path
filename="${filename///Volumes}"

# loop over backups in reverse order
tmutil listbackups | tail -1000 -r |
while IFS= read -r line; do
    if [ -e "$line$filename" ]; then
        ls -ald "$line$filename"
    else
        echo "not in $line"
    fi
done
2

Assuming that you didn't change the name of your main drive from 'Macintosh HD' to something else, you can run

ls -l /Volumes/Time\ Machine/Backups.backupdb/$(hostname -s)/*/Macintosh\ HD/$(realpath FILENAME)

to see all versions stored in TimeMachine.

PS realpath is only available if you have GNU coreutils installed (e.g. via brew). Otherwise use $(pwd)/FILENAME or (if this doesn't work because there are some symlinks involved) specify the full path instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .