How to back up your Mac config and apps from Terminal (using brew, conda, pip and mackup)

When you are using you Mac daily you begin to use several apps almost without thinking. But when you have to migrate to new Mac (or Linux) you realize how many apps and custom settings are you missing.

Context

I want to back up my Mac settings and be able to use or restore them in the same or another Mac. I mean Mac because:

  1. brew is mainly used in Mac, but also available in Linux and WSL) and
  2. mackup is mainly for macOS (but should also support Linux)

We will back up the following tool sets:

  • brew packages as a list of installed packages
  • conda environments
  • all apps supported by mackup
  • pip packages

Brew

Export apps to a Brewfile

brew bundle dump # dump the app list to the current directory

brew bundle dump --file=~/Brewfile # dump the app list to a specific location 

Import (install) apps from a Brewfile

brew bundle --file=~/.private/Brewfile

Conda

Export 1 (one) conda environment (env)

To export just one environment you can do the following:

conda activate my_env
conda env export > my_env.yml
conda deactivate

Export all conda environments (env) in one command

But usually you have several environments (at least I do) and you would want to export all of them at the same time. In that case, you may do the following source

for env in $(conda env list | cut -d" " -f1); do 
   if [[ ${env:0:1} == "#" ]] ; then continue; fi;
   conda env export -n $env > ${env}.yml
done

Create a conda env from a YAML file

This will create a .yml file with the name of the env for each of the envs you have.

To create an environment from a .yml file

conda env create -f environment.yml

Mackup

mackup backup # to backup
mackup restore # to restore

PIP

To export all the dependencies in a python environment

pip freeze > requirements.txt

tT import (or install) all the dependencies from a text-file

pip install -f requirements.txt

References

Comments

Comments powered by Disqus