Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Selective Restores on macOS

Note: This post is not yet finished

I have owned a Mac continuously for the last 8 years as part of my job and used it full time both professionally and personally. Over that time I have carried a lot of crap from machine to machine, and a lot of that was very work specific. Certs, credentials, applications, and other various configurations and files. I've always just performed a full Time Machine restore each time I upgraded.

I recently switched employers, and wanted to start mostly fresh, but with the ability to keep some of the more generic configurations on my Mac like VIM configurations, and the ability to bring over personal files. I wasn't sure how I was going to approach this at first. I imagined, that I would just take a Time Machine backup, perform a fresh install, and then use the Migration Assistant to uncheck some things I don't want.

Using the Time Machine backup and Migration Assistant, seemed like a great idea, although Migration Assistant doesn't give you the fine grain control over individual files and directories that are more than 1 level deep.

Fortunately the Time Machine backup is easy to navigate, and with a little help from cp and rsync I was in business.

First, perform fresh install of macOS, and then once you get the OS up and running, plug in your Time Machine backup. The files from the Time Machine backup should be accessible at a path like:

/Volumes/Untitled/Backups.backupdb/HOSTNAME/Latest/Macintosh HD/

I'd recommend just switching to this directory to do your work:

cd /Volumes/Untitled/Backups.backupdb/HOSTNAME/Latest/Macintosh\ HD/

A little tip that I can offer here, is to start with "visibile" (non-hidden) files and directories, and a good way to separate them is to first start with your home directory and just do a simple ls:

cd Users/USERNAME
ls

The output will look something like:

Applications          VirtualBox            int-fail.txt
Desktop               alice                 octal.txt
Documents             ansible               onboarding.txt
Downloads             ansible_testing       ooto.txt
Dropbox               apps.txt              projects
Library               ascript               python_venvs_bak
Movies                bin                   roms
Music                 buildpy.txt           ssl
Pictures              docker                todelete.txt
Prezi                 drone                 venvs
Public                funky                 webhook-phonehome.txt
Sites                 git
VMs                   go

From here, we'll use rsync, and work column by column to make it easier:

rsync -av Applications Desktop Documents Movies Music Pictures Prezi Public Sites /Users/USERNAME/

You'll notice a few things in that command. First, I skipped some directories like Library and Dropbox. Dropbox will re-sync on it's own, and I don't want Library as I am trying to start clean. I'll grab a few individual things from Library later. Additionally, there are no trailing slashes on any of those directories; This is to support rsync, and make sure we are copying things correctly, as we want to copy the directories to our new home directory, and not just the contents of those directories. Include the trainling slash, and you will end of with a bunch of things directly in your home directory you weren't anticipating on.

Run this through for the remaining directories and files.

Next, we'll do the hidden files and directories:

ls -a | grep '^\.'

You won't get all of the columns you did before, but you could step through it with head or tail if you wanted.

Proceed rsyncing with the hidden files and directories, omitting anything you don't want, or that will be rebuilt later.

Now is when I went cherry picking some individual files from Library such as:

Library/Fonts/Monaco+for+Powerline.otf
Library/Preferences/com.googlecode.iterm2.plist
Library/Containers/com.mactaris.Webcam-Settings/Data/Library/Preferences/com.mactaris.Webcam-Settings.plist

Something else to note here, is that I didn't restore anything from /Applications, although feel free to do so. I wanted to try and start as fresh as possible, so I installed everything from scratch. On one hand I found that an app I used called DashExpander no longer exists, so I just used the built in text replacement functionality in macOS. Maybe, I'll go back and grab this old app.

Outside of using Time Machine for backups, I've recently started using Arq Backup, paired with Backblaze B2 for storage. I found in my travels that I deleted something a while back that I needed, and was able to get that from my Arq backups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment