Restoring from Time Machine backup relocates home directories

Ryan Schmidt ryandesign at macports.org
Fri Sep 15 02:32:53 UTC 2017


I recently reinstalled macOS and, during the setup process, restored from a Time Machine backup. One would think that after restoration, the machine would be in a state sufficiently similar to the one it was in at backup time, but for our purposes, it is not, specifically with regard to user accounts. I don't know how to solve this in MacPorts yet, but I want to at least document the problems I've observed.

I had numerous ports installed that create their own user accounts with add_users or add_user, and of course MacPorts has its macports user. For each of these users, I could select if I wanted the user to be restored, but if so, it indicated that it would relocate that user's home directory to /Users; if a user is to be restored, there is no option presented not to move its home directory. I chose to accept the defaults and restore all users.

This had consequences that we do not want. For example, the macports user's home directory is supposed to be at /opt/local/var/macports/home, but the restoration process moved that directory to /Users/macports and changed the NFSHomeDirectory of the user account to match. In the case of the macports user, MacPorts doesn't store anything important in this directory, but it does expect the directory to exist at its usual location.

Some ports may have important data in their users' home directories. postgresql96-server for example sets its user's home directory to /opt/local/var/db/postgresql96. That directory contains the database data. If it is moved, postgresql won't be able to find its databases anymore.

Things can get even worse than that. I had at one point installed the port rbldnsd. It creates a user _rbldnsd with the home directory set to /opt/local/sbin. Upon restoration, /opt/local/sbin was moved to /Users/_rbldnsd, making all programs in /opt/local/sbin unavailable until it was moved back.

Fixing these problems afterward is tedious. For each directory in /Users, the user has to determine whether it belongs to a port, and if so, which port; it's not always clear. For example, I had a directory /Users/cyrus, and we have three ports whose names begin with "cyrus", so I had to read the Portfiles to determine which one had created the user. The Portfile also has to be consulted to determine what the correct home directory is. Then the directory has to be moved back to where it belongs, and the dscl command must be used to change the NFSHomeDirectory, such as:

sudo mv /Users/macports /opt/local/var/macports/home
sudo dscl . -change /Users/macports NFSHomeDirectory /Users/macports /opt/local/var/macports/home

The restoration process also created the Desktop, Documents, Downloads, Library, Movies, Music, Pictures, and Sites folders in each home directory, which we don't want.

In the case of rbldnsd, hopefully it doesn't actually require the home directory to be /opt/local/sbin, so we could change it in the Portfile. And that seems to be the only port that uses that unusual home directory. But MacPorts only sets the home directory when the user is created; anyone who ever installed the port before won't have it automatically fixed. We could add code to that port to edit the user if it already exists, or we could do that in MacPorts base, since it's possible that other ports might from time to time want to change their user's home directory.

If we wanted to detect or even automatically fix this in MacPorts, we could check whether /opt/local/var/macports/home exists. If not, we could check it /Users/macports exists. If so, we could refer the user to documentation on how to fix it. To fix it automatically would probably require MacPorts separately keeping track of the users it created, along with their settings such as home directory.





More information about the macports-dev mailing list