Last active
October 26, 2024 19:56
-
-
Save aheissenberger/fcc597f550c621e57a5deafaf7a2fd4c to your computer and use it in GitHub Desktop.
Exclude package folder e.g. node_modules from being backuped by MacOS Time Machine
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
#!/bin/sh | |
#set -x | |
EXCLUDEFOLDERNAME=${3:-"node_modules"} | |
get_realpath () | |
{ | |
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" | |
} | |
SEARCHPATH="$(get_realpath ${2:-"${HOME}"})" | |
list_tm () | |
{ | |
find "${SEARCHPATH}" -xattrname "com.apple.metadata:com_apple_backup_excludeItem" -name "${EXCLUDEFOLDERNAME}" -type d -prune | |
} | |
run_tm () | |
{ | |
find "${SEARCHPATH}" -name "${EXCLUDEFOLDERNAME}" -type d -prune -print0 -exec tmutil addexclusion "{}" \; | |
} | |
reset_tm () | |
{ | |
find "${SEARCHPATH}" -xattrname "com.apple.metadata:com_apple_backup_excludeItem" -name "${EXCLUDEFOLDERNAME}" -type d -prune -print0 -exec tmutil removeexclusion "{}" \; | |
} | |
case "${1}" in | |
list) | |
list_tm | |
;; | |
run) | |
run_tm | |
;; | |
reset) | |
reset_tm | |
;; | |
*) | |
echo $"Usage: $0 {run|list|reset} [search path (Default: '${HOME}')] [exclude folder name (Default: 'node_modules')]" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment