DEV Community

Diego Carrasco Gubernatis
Diego Carrasco Gubernatis

Posted on • Originally published at diegocarrasco.com on

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 

Enter fullscreen mode Exit fullscreen mode

Import (install) apps from a Brewfile

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Mackup

mackup backup # to backup
mackup restore # to restore

Enter fullscreen mode Exit fullscreen mode

PIP

To export all the dependencies in a python environment

pip freeze > requirements.txt

Enter fullscreen mode Exit fullscreen mode

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

pip install -f requirements.txt

Enter fullscreen mode Exit fullscreen mode

References

Top comments (0)