- Background
- How to adopt/customize the scripts to your own settings
- Pre-requisites
- Basic setup
- Advanced setup (in addition to the basic setup if you want to capture other files in an encrypted private git repo)
- Finally...
- Ongoing tasks to keep your backup up-to-date on a regular basis
- Extras/Details
- Attributions & Thanks
This repo is used to backup and easily reimage a new macos system. It contains the common dotfiles as well as the scripts that I use as the backup/restore strategy.
These scripts are idempotent and can run on a vanilla OS as well as once the whole setup has been completed.
Each script will warn the users if its skipping a step, and if you want to rerun the script but force that step, you just need to delete the control if
condition (you should have a basic understanding of shell programming to figure out what to delete/how to force without bypass).
All of the folder structures and the setup/backup operations are governed by the environment variables defined here. Please read the explanation of each variable in the same and edit appropriately.
If you want to be able to re-image a new machine with your own settings (and overridden choices), and you do not want to repeat these steps manually, you would want to fork my repo and make appropriate changes into your fork.
In your forked repo, make the following changes, commit and push via the Github web-UI itself (for the first time before running the scripts). Once the above steps are done, and committed into your fork, then everytime you need to run the setup, you can run the curl
commands that point to your fork:
- Only in this file,
GettingStarted-Basic.md
andfiles/--HOME--/.shellrc
files (and nowhere else): Find and replace the strings that reference my usernames to your equivalent ones (for eg, you can search forvraravam
andavijayr
and replace them with your values). - Optional: The nested folder names that you choose for your setup (as referred to by
PROJECTS_BASE_DIR
,PERSONAL_CONFIGS_DIR
,PERSONAL_PROFILES_DIR
,PERSONAL_BIN_DIR
, andDOTFILES_DIR
in thefiles/--HOME--/.shellrc
file) should be reflected in the folder structure of the nested folders in thefiles
directory of the committed github repo itself. For eg, I havePROJECTS_BASE_DIR="${HOME}/dev"
, and if your setup usesworkspace
instead ofdev
, then, in your forked repository, the folder namefiles/dev
should be renamed tofiles/workspace
and so on. - Review all entries in the
${HOME}/Brewfile
, and ensure that there are no unwanted libraries/applications. If you have any doubts (if comparing with my Brewfile), you will need to search the internet for the uses of those libraries/applications and decide whether to keep it or not.
-
My recommendation is to always have all your customizations as a single commit on top of the upstream. This allows to easily rebase and adopt new changes in the future.
-
Run the
git upreb
command when in this repo's folder (${HOME}/.bin-oss
). Most of the times, this should simply rebase your changes on top of the latest upstream master- Hint: Before pushing your changes to your remote, if you want to ensure (diff) that your old changes are retained (for eg in
Brewfile
) and no new/unnecessary changes are present, you can run the following 2 commands and review the diffs manually
git diff @{u} # will diff your local HEAD against the remote HEAD of your own fork. Please remember that this diff will show new changes that I have made in my repo, and which are now going-to-be-adopted into yours. It's a good idea to remove entries in Brewfile that you won't need git diff upstream/`git br` # will diff your local HEAD against the remote HEAD of MY repo. These changes should be exactly the changes that you had done previously (most likely only in GettingStarted-Basic.md, files/--HOME--/.shellrc and files/--HOME--/Brewfile)
- Hint: Before pushing your changes to your remote, if you want to ensure (diff) that your old changes are retained (for eg in
-
You will have to force-push to your fork's remote after the above step. To accomplish this, I recommend using
git push --force-with-lease
-
After the above step, it is always recommended to run the
install-dotfiles.rb
script once to ensure all (non symlinked) changes are setup on your machine correctly. -
In case there are any other changes that might be needed after updating, these steps will be detailed in the changelog. In such rare cases, you might have to run the appropriate steps in sequence as detailed out in that section.
-
After updating/catching-up, it is recommended to quit and restart the terminal so that all "in session memory" aliases, etc are up-to-date so that the files are sourced correctly.
- Especially if you are making changes to the fresh-install scripts and want to test it out on a vanilla OS, you can change the github urls to refer to your branch in these files
GettingStarted-Basic.md
andfiles/--HOME--/.shellrc
. For eg, if your PR branch is calledzdotdir-fixes
, you can search forDOTFILES_BRANCH=
in those files, and replacemaster
withzddotdir-fixes
. Once your PR is tested and approved, please remember to revertzddotdir-fixes
back tomaster
and then merge the PR into the main working branch.
If you want to capture data from your current mac, please follow the instructions here
The backup strategy is split into 2 stages - both of which are run by the same script. The basic "getting started" provides the instructions for the most common/basic setup. This covers everything that a typical user might need - without the need to backup other parts of the existing laptop. The "advanced" setup is the set of final steps to capture your application preferences (both system apps as well as custom apps) and back them up into an encrypted remote repository. Currently this kind of private, fully-encrypted and free service is offered only by keybase. Instructions for this setup can be found here
With this latest version, the files/--HOME--/Brewfile
will be run only with the bare minimum of formulae. Once the process completes, and you restart the Terminal app, you would want to run bupc
so that all the other applications can be installed.
Once the above is done, and if you have setup the keybase-based home repo, profile repo, etc - you can then re-import your exported preferences from the pre-requisites section.
Of course, you will have to manually take snapshots of your machine for backup from time-to-time as an ongoing activity. This can be done using the scripts/capture-defaults.sh
script and pushing into the remote repo of your home folder. (More details can be found in the next section.)
As a summary, these files will typically have changes between your setup and mine:
GettingStarted-Basic.md
(references to your usernames instead of mine, and typically any other changes that you introduce in thefiles/--HOME--/.shellrc
- look below)files/--HOME--/.gitconfig
(theIncludeIf
line to match your global/base configuration filename)files/--HOME--/.shellrc
(GH_USERNAME
,KEYBASE_USERNAME
, and other changeable env vars to control which steps to perform vs which to bypass)files/--HOME--/Brewfile
(the list of applications and command-line utilities that you choose to install in your local machine)scripts/capture-defaults.sh
(what application preferences that you choose to backup - based on the entries in theBrewfile
)scripts/fresh-install-of-osx.sh
(what applications you choose to set as login items on every reboot)
The backup strategy is not a one-off activity. It will require you to take snapshots from time-to-time. Similarly, adherance to maintainence of the "catalogs" will need to be strictly upheld for the backup strategy to be effective.
- Ensure that the software catalogs (
files/--HOME--/Brewfile
,scripts/fresh-install-of-osx.sh
,scripts/capture-defaults.sh
) are always kept in sync with the actual applications that you install and use - Ensure that the git repo catalogs that you are "tracking" in the
${PERSONAL_CONFIGS_DIR}/repositories-*.yml
files are kept up-to-date so that resurrection in your new machine will be seamless - Ensure to run the
scripts/capture-defaults.sh
(with the export switch) to export and capture/backup your preferences for all installed applications from your current machine. If you want to automate the repetitive running of this and possibly other scripts/commands, you can use the system-level cronjobs to set this up!
Some utility scripts have been provided in this repo - which you can use to manage the backup strategy in a better fashion. Details can be found here
These folks have contributed to this codebase till date:
- @arunvelsriram
- @shaz-ahammed
- @srihari-sridharan-tw
- @jotheeswaran-dev