11

How to add the node_modules folder paths to time machine ignore paths. These folders are like tmp data for backups. These are very dense folders and also slow down TM. Is there is a txt file which can be appended? Maybe a command line which can append to the config.

thevikas
  • 429

4 Answers4

27

I'm one of the maintainers of Asimov, a free macOS utility for automatically excluding development dependencies from Time Machine backups (npm, Composer, RubyGems, and more). It was designed for this very purpose ::looks begrudgingly at node_modules/::

The easiest way to install Asimov is via Homebrew (brew install asimov), but the GitHub repo also has manual installation instructions. Once installed, a cron job runs every day to find development dependencies and automatically exclude them from Time Machine via tmutil (mentioned above).

One more benefit is that Asimov checks for the dependency declarations (in the case of node_modules/, a package.json file) before excluding the directory from backups.

mmmmmm
  • 30,160
  • 2
    Just wanted to say thank you for building / sharing this utility. Exactly what I was looking for. Thank you! – tdc Oct 15 '22 at 14:05
  • 1
    FWIW there is also https://github.com/tg44/heptapod available with a bit more "options". – Tony Jan 25 '23 at 02:23
4

There're several approaches mentioned in this gist.

  1. Using tmutil addexclusion
find `pwd` -type d -maxdepth 3 -name 'node_modules' | xargs -n 1 tmutil addexclusion
  1. Using tmignore which automatically finds all Git repositories on your disk and excludes all paths matching .gitignore files. I've just tried it and it works great. You can also set up a script to check your disk periodically.
Tom Ehrlich
  • 141
  • 2
  • Is there a tmutil command to show a list of excluded files/folders? I would like to confirm that the command has worked before actually running the backup. – Gene Parcellano Feb 27 '21 at 19:13
  • @GeneParcellano I don't know about any. You could use tmutil isexcluded [path] to check specific path – Tom Ehrlich Mar 02 '21 at 13:05
  • Note that in more recent versions of macOS you might need to add the -p switch to tmutil. Also, you need to enable "Full Disk Access" privileges for Terminal otherwise the following appears when running tmutil:

    tmutil: addexclusion requires Full Disk Access privileges. To allow this operation, select Full Disk Access in the Privacy tab of the Security & Privacy preference pane, and add Terminal to the list of applications which are allowed Full Disk Access.

    – Anthony Mar 29 '22 at 09:04
2

You can manage the list of ignored folders in the Time Machine preferences.

enter image description here

nohillside
  • 100,768
  • 4
    this I know but its very hard to manage the GUI when a techie machine creates and destroys a dozen node project folders every day – thevikas Mar 29 '20 at 05:46
0

You can leverage tmutil Time Machine utility for managing such exclusions. Note that in more recent versions of macOS you might need to add the fixed path -p switch to tmutil as well as hold root privileges. Also, you need to enable "Full Disk Access" privileges for Terminal beforehand, otherwise the following appears when running tmutil separately:

tmutil: addexclusion requires Full Disk Access privileges. To allow this operation, select Full Disk Access in the Privacy tab of the Security & Privacy preference pane, and add Terminal to the list of applications which are allowed Full Disk Access.

find pwd -type d -maxdepth 3 -name 'node_modules' | xargs -n 1 sudo tmutil addexclusion -p

PS. Because TM's config does not allow for regular expressions, you need to rerun this command whenever you create new project directories that needs similar exclusion.

Anthony
  • 66