Note: This post was originally published on my blog.
On macOS, TimeMachine is a great tool for backing up your Mac. However, if you work on a lot of JavaScript projects, you probably have a couple of node_modules
folders that don't need to be included in your backup. Here is how you can list, add and remove folders from your Time Machine backup.
# List currently excluded node_modules folders
$> sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'" | grep "node_modules"
# Exclude a folder from backup
$> tmutil addexclusion ABSOLUTE_PATH_TO_FOLDER
# Remove folder from the list of excluded folders
$> tmutil removeexclusion ABSOLUTE_PATH_TO_FOLDER
Of course, this also works with any other folder, not only node_modules
.
If you don't want to use the terminal, you can also use macOS' system settings: System Settings -> General -> Time Machine -> Options
(for macOS Sonoma).
Top comments (2)
Thanks a lot!
Just a simple script to exclude all the 'node_modules' from a folder (e.g: /usr/user/my-dev-folder/)
find <DEV_FOLDER_ABSOLUTE_PATH> -type d -name 'node_modules' -prune -exec tmutil addexclusion {} \;
It have to be executed from root path to get the absolute path
Thanks @michael_bertuzzi_7c9eeb32, that is a nice way to exclude all
node_modules
folders within a folder recursively 👍