How to backup and restore /opt with Time Machine on macOS High Sierra?

I have an old MacBook Pro running High Sierra. Time Machine backs up /Users but not /opt.

The Time Machine preferences let me exclude directories, but does not let me add directories that I want to back up.

How can I get Time Machine to backup /opt on High Sierra and how can I restore it?


How can I get Time Machine to backup /opt on High Sierra?

You don't need to do anything special to back it up: Time Machine backs up all folders on your Mac.

However, you may get the impression that /opt (and other folders like /bin or /cores, as you mention in your comment) are not included because the Finder hides those folders by default: enter image description here

But don't let the Finder mislead you:

  • either press ShiftCommand. to let the Finder display all folders (press ShiftCommand. again to hide them),
  • or open Terminal, list the contents of the backup folder and you will see that everything is there: enter image description here

How can I restore /opt?

Proceed as follows:

  • Open a Finder window.
  • Enter Time Machine.
  • Press ShiftCommandG and enter / to display the root folder of your drive.
  • Press ShiftCommand. to display hidden folders. You should see /opt now.
  • Browse the timeline on the right-hand side and select the desired date.
  • Select /opt.
  • Press Restore. Note that Time Machine will probably ask whether you want to keep a copy of your current files.