Last active
January 2, 2018 18:57
-
-
Save tralston/07ffbee7a3d10aad2c40a5f6646857e7 to your computer and use it in GitHub Desktop.
[Time Machine Clean Up]
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
# Prerequisites | |
# - the `hln` command, which on mac can be installed via `brew install hardlink-osx` | |
# - various time machine cleaning scripts: tmdejunk, tmdeempty, tmdeduphl, tmdeduphldir | |
# In the time machine volume, under Backups.backupdb/<Machine Name> | |
# Note: this only prunes the hardlinks in the /Users/ folder of each backup snapshot. | |
# The following code will find the /Users folder within each snapshot, and then run the tmdejunk command, followed by tmclean command. It will prune empty folders, prune hardlink folders, then delete hardlink files, then prune empty folders again. This process can take several hours depending on how many snapshots you have backed up | |
find . -maxdepth 3 -iname "Users" -execdir bash -c "cd {} && echo 'Starting dejunk' ; pwd ; tmdejunk | ts ; tmclean | ts" \; | |
# Once that's done, descend into the first backup snapshot, down to the Users folder | |
cd <e.g. 2011-11-16-060719>/<eg. Macintosh HD>/Users | |
# Since the empty folder prune command (tmdeempty) is one-pass only, run tmdeempty repeatedly until there's no more output | |
tmdeempty | |
# Create a mirror location to restore this to. I've chosen a folder /compare/ outside of my time machine drive to do deduplication later. To get the path after /compare/, I would just copy the path of the current folder from <Machine>/<snapshot date>/<HDD name> then paste it | |
mkdir -p '/compare/<Machine Name>/<snapshot date>/<HDD name>' | |
# If you run this command right after the last one, you can use the special argument !$ which uses the last parameter from the last command, otherwise you'll have to paste the full path in again | |
tmutil restore -v . !$ | |
cd ../../.. | |
# At this point, you may want to verify that the newly restored data copied over correctly, be looking at the folder size. Beyond this point, your data will be permanently deleted on the time machine drive | |
sudo tmutil delete <snapshot date> | |
# That snapshot is gone! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment