Last active
August 23, 2024 02:15
-
-
Save andrewpetrochenkov/0753d79c132ae6895e389667c1f44bc0 to your computer and use it in GitHub Desktop.
macOS Time Machine exclusions
This file contains 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
#!/usr/bin/env bash | |
{ set +x; } 2>/dev/null | |
IFS=$'\n' | |
set "$@" $(find ~ -name ".*" ! -name ".CFUserTextEncoding" ! -type l -mindepth 1 -maxdepth 1) # dotfiles | |
set "$@" $(find ~ -name "Google *" -mindepth 1 -maxdepth 1) # Google Drive | |
set "$@" ~/git # store on github/etc :) | |
set "$@" ~/node_modules | |
set "$@" ~/Applications # install apps with brew cask | |
set "$@" ~/Desktop ~/Downloads ~/Movies ~/Music ~/Pictures | |
set "$@" ~/Library/Application\ Support ~/Library/Caches ~/Library/Containers ~/Library/Google ~/Library/Internet\ Plug-Ins ~/Library/LaunchAgents ~/Library/Logs ~/Library/Mail ~/Library/Messages ~/Library/Mail ~/Library/Metadata ~/Library/QuickLook ~/Library/Safari ~/Library/Saved\ Application\ State ~/Library/Screen\ Savers ~/Library/Sharing ~/Library/Suggestions | |
set "$@" $(find /usr/local -type d ! -type l -mindepth 1 -maxdepth 1) # brew, logs, etc | |
set "$@" /opt # MacPorts | |
set "$@" /vm # swapfile | |
set "$@" /var/db/diagnostics /var/db/folders /var/db/uuidtext /var/db/vm /var/log /var/tmp | |
set "$@" /Library/Developer # Xcode. xcode-select --install, https://developer.apple.com/download/more/ | |
set "$@" /Library/Java # brew cask install java | |
set "$@" /Library/Caches /Library/Desktop\ Pictures /Library/Documentation /Library/Modem\ Scripts /Library/Python /Library/Ruby/Gems /Library/Screen\ Savers /Library/Scripts /Library/Services /Library/Spotlight /Library/Updates /Library/User\ Pictures /Library/WebServer /Library/Widgets | |
languages="$(defaults read .GlobalPreferences AppleLanguages | awk -F'"' '{print $2}' | sed '/^$/d' | awk -F'-' '{print $1}' | grep -v en)" | |
# /System/Library/Speech/Voices/<name>.SpeechVoice | |
set "$@" $( | |
folders="$(find /System/Library/Speech/Voices -type d -mindepth 1 -maxdepth 1)" | |
[[ -n "$folders" ]] && while IFS= read path; do | |
/usr/libexec/PlistBuddy -c "Print :VoiceAttributes:VoiceLocaleIdentifier" "$path"/Contents/Info.plist 2> /dev/null | grep -q "$languages" || echo "$path" | |
done <<< "$folders" | |
) | |
set "$@" /System/Library/Caches | |
# /System/Library/LinguisticData/<code>/, /System/Library/LinguisticData/RequiredAssets_<code>.bundle/ | |
set "$@" $( | |
set -- ! -name "_*" ! -name "*en*" | |
[[ -n "$languages" ]] && while IFS= read lang; do | |
set -- "$@" ! -name "*$lang*" | |
done <<< "$languages" | |
find /System/Library/LinguisticData -type d "$@" -mindepth 1 -maxdepth 1 | |
) | |
n=0 | |
sudo /usr/libexec/PlistBuddy -c "Delete SkipPaths" /Library/Preferences/com.apple.TimeMachine.plist | |
sudo /usr/libexec/PlistBuddy -c "Add SkipPaths array" /Library/Preferences/com.apple.TimeMachine.plist | |
while [[ $# != 0 ]]; do | |
[[ -n "$1" ]] && [ -e "$1" ] && { | |
sudo /usr/libexec/PlistBuddy -c "Add SkipPaths:$n string '$1'" /Library/Preferences/com.apple.TimeMachine.plist || exit | |
sudo tmutil addexclusion "$1" | |
((n++)) | |
} | |
shift | |
done | |
killall cfprefsd;: | |
# /usr/libexec/PlistBuddy -c "Add SkipPaths:$n string '<path>'" /Library/Preferences/com.apple.TimeMachine.plist | |
# defaults read /Library/Preferences/com.apple.TimeMachine.plist SkipPaths | |
# tmutil addexclusion <path> # not works with /System if SIP enabled | |
# mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'" | |
# tmutil isexcluded <path> # check | |
# default exclusions: | |
# /System/Library/CoreServices/backupd.bundle/Contents/Resources/StdExclusions.plist | |
# find big items: | |
# find <path> -mindepth 1 -maxdepth 1 -exec bash -c 'set -x;du -sh "$0"' {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment