Last active
May 4, 2022 01:29
-
-
Save poma/0e0ccbfca2dd5ba62f18d3b45a8bfc77 to your computer and use it in GitHub Desktop.
Exclude dependency dirs from Time Machine backups
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
tmutil_exclude() { | |
# todo: recurse to parent dirs to support commands that execute in project subdirs | |
DIR=$1 | |
DEP_FILE=$2 | |
if [ -d "$DIR" ] && [ -f "$DEP_FILE" ] && ! tmutil isexcluded "$DIR" | grep -q '\[Excluded\]'; then | |
tmutil addexclusion "$DIR" | |
echo "tmutil: ${DIR} has been excluded from Time Machine backups" | |
fi | |
} | |
__npm_wrapper () { | |
command npm "$@" | |
EXIT_CODE=$? | |
tmutil_exclude "node_modules" "package.json" | |
return $EXIT_CODE | |
} | |
__cargo_wrapper () { | |
command cargo "$@" | |
EXIT_CODE=$? | |
tmutil_exclude "target" "cargo.toml" | |
return $EXIT_CODE | |
} | |
alias npm=__npm_wrapper | |
alias cargo=__cargo_wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! Will this run on MacOS Monterey?
I'm currently looking to implement something like this, but while this seems to work perfect on Catalina I'm not sure it does on Monterey (the dry run doesn't yield a list of excluded paths).
I really would love to find a (semi) automated way to exclude
node_modules
and.venv
folders from my Time Machine backups.