Skip to content

Instantly share code, notes, and snippets.

@sohocoke
Last active September 3, 2019 12:01
Show Gist options
  • Save sohocoke/7f0e2a05c9ae2a26ba4ad45db3d886e4 to your computer and use it in GitHub Desktop.
Save sohocoke/7f0e2a05c9ae2a26ba4ad45db3d886e4 to your computer and use it in GitHub Desktop.
Copy a file from a bunch of Time Machine backup directories.
#! /bin/zsh
# Copy a file from a bunch of TM backup sets.
# --
# This a rough-and-ready alternative to using the Time Machine UI to find and
# recover the right version of a file, which can take an eternity with networked
# backup volumes.
# tweak the values and run in a terminal app that has full disk access permissions.
#== change these to suitable values for your recovery attempt.
# what to recover.
# note the path starts with the name of the volume.
path_to_recover=Macintosh\ HD/Users/ilo/dev/src/bigbearlabs/webbuddy-container/.contexter/1E7A2A51-DFBF-44D8-8A41-7CB632E6FBF2.tabset
# where to recover the files to.
# ensure this directory exists.
recovery_dir=~/tmp/recovery
# the path to the backups for your machine.
# ensure the TM volume is mounted.
tm_machine_dir=/Volumes/Time\ Machine\ Backups/Backups.backupdb/picklerick
# the pattern that specifies the backup sets to target.
# this example will recover files for all the backups from July 2019.
pattern="2019-07"
#== logic.
lscmd='ls -rt $tm_machine_dir | grep $pattern'
# cmd='rsync -av $tm_machine_dir/$dir/$path_to_recover $recovery_dir/$dir/'
cmd='ls $tm_machine_dir/$dir/$path_to_recover'
for dir in `eval $lscmd`; do
eval $cmd
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment