Important This is basically all thanks to the incredible work of Clint M, I take no credit for the actual logic that goes into the backup process, all I did was upgrade the build pipeline for this to make the latest version available on homebrew, since the original repo hadn't seen any updates for the last couple of years. Anyways, this is just to say thanks to Clint, and please show him your thanks if you find this at all useful.
Maybe I'll keep working on this and add some more stuff to it eventually...
A tool to backup and restore Mac preferences.
This will backup and restore Application as well as System Preferences.
I wanted a solution to back up my settings for my Mac and one didn't really exist. Time Machine is a bit overkill for this.
At first I was trying to create a bash script to restore all my settings. I was trying to adapt the .osx
.macos
file from Mathias Bynens. I noticed that some of the cases for the domains were wrong/outdated and weren't actually changing the preferences they were intended to change.
Running defaults write
with the wrong case for the keys or domains also causes problems as the defaults command may fail silently.
- Mac OS X greater than 10.9 (maybe older… didn't test)
- Python 3.6
Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install sijanc147/formulas/macprefs
You can set the MACPREFS_BACKUP_DIR environment variable to specify where you'd like to backup the prefs too.
The default backup directory is ~/Dropbox/MacPrefsBackup
.
export MACPREFS_BACKUP_DIR="$HOME/SomeOtherDir"
You can backup your preferences by running:
macprefs backup
You can also choose to backup selected preferences by running:
macprefs backup -t system_preferences startup_items preferences app_store_preferences internet_accounts
Following backups are currently possible:
system_preferences
: Backs up /Library/Preferences/com.apple.PowerManagement.plist
or /Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist
, depending on the availability.
startup_items
: Backs up user launch agents
, system launch agents
and system daemon agents
dotfiles
: Backs up all your dotfiles
from your home directory.
shared_file_lists
: Backs up ~/Library/Application Support/com.apple.sharedfilelist/
preferences
: Backs up ~/Library/Preferences/
app_store_preferences
: Backs up your App Store preferences
internet_accounts
: Backs up your ~/Library/Accounts
Make sure you have given full disk access to your terminal app for this script to work properly. You can run this command to open system preference window
open "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"
You can restore your preferences by running:
macprefs restore
Similar to Backing, you can choose to restore selected preferences by running
macprefs restore -t system_preferences startup_items preferences app_store_preferences internet_accounts
- You might have to log out and then log back in for the settings to take effect.
- Create a new user on your Mac
- Make sure he's in the admin group
- Log in as that user
- Do the Getting Started steps
- Update the Config
- Grant the admin group read access to your backup files (substitute ~/Dropbox with your backup dir if different)
# grant admin group read on ~/Dropbox
chmod a "group:admin allow list,search,readattr,readextattr,readsecurity" ~/Dropbox/
# grant admin group read on ~/Dropbox/MacPrefsBackup recursively (-R)
chmod -R a "group:admin allow list,search,readattr,readextattr,readsecurity" ~/Dropbox/MacPrefsBackup
# grant dir list (execute) permission on all subfolders of ~/Dropbox recursively (-R)
chmod -R X ~/Dropbox
# remove execute permission for other on all files and folders because
# X adds other permissions
chmod -R o=-x ~/Dropbox
- Run the Restore
- Log out and log back in to confirm the restore succeeded
- Backs up all the preferences in
~/Library/Preferences
and/Library/Preferences
- Backs up all 'Internet Accounts' databases in
~/Library/Accounts
- Backs up PowerManagement preferences
- Backs up shared file lists (Finder Favorites in Sidebar)
~/Library/Application Support/com.apple.sharedfilelist
- Backups up dotfiles ($HOME/.* (e.g. .bash_profile))
- Backups up the $HOME/.ssh dir
- Backups launch items
/Library/LaunchAgents
,/Library/LaunchDaemons
,~/Library/LaunchAgents
-
- These scripts makes copies of plist files in
~/Library/Preferences
and is not compatible with the way Mackup creates symlinks for some of these files. On the bright side though, if you use this as well as Mackup to backup and restore, everything should just work. Just remember that any preferences Mackup backs up won't be backed up by this tool.
- These scripts makes copies of plist files in
-
- When you run
defaults write
and use the wrong/old case for the domain you can create a new plist file with the wrong case (e.g. com.apple.addressbook instead of com.apple.AddressBook). - The
defaults
app has a tendency to fail silently for some things. You might be trying to use olddefaults write
commands where the key is the wrong name. - Because of the above 2 reasons maintaining a bunch of
defaults write
commands in bash script can be error prone and the defaults command will fail silently.
- When you run
- Backup and restore
/Library/Preferences
(e.g. PowerManagement) - Installable via homebrew
- Backup and restore shared file lists (Finder sidebar)
~/Library/Application Support/com.apple.sharedfilelist
- Backup and restore dotfiles (e.g. $HOME/.bash_profile)
- $HOME/.ssh dir
- Startup Items
/Library/LaunchAgents
,/Library/LaunchDaemons
,~/Library/LaunchAgents
- Verify backup and restore
- Write a util to generate a
bash
script ofdefaults write
commands by diffing a new user account against the owned account
- If you find a problem or a have a question feel free to file a bug here and/or send a pull request and I'll be happy to look at it and/or merge it.
- Fork and clone then cd to this git repository
- Run
pip install -r requirements.txt
- Run
make test lint
(make sure you've done the Getting Started)
- Make your changes and push them to github
- Make sure your changes have tests and pass linting
- Open a pull request