Skip to content

Instantly share code, notes, and snippets.

@elehcim
Last active December 13, 2017 11:11
Show Gist options
  • Save elehcim/24c15cd57fe36b16298a8d6473da706c to your computer and use it in GitHub Desktop.
Save elehcim/24c15cd57fe36b16298a8d6473da706c to your computer and use it in GitHub Desktop.
Script to backup all the conda environments and save them in .yml files ordered by day and time of the day
#!/bin/bash
# Parse conda env list
CONDA_ENVS=`conda env list --json | python -c 'import json,sys,os;obj=json.load(sys.stdin);print(" ".join(os.path.basename(p) for p in obj["envs"]))'`
# Add the root env because "conda env list --json" doesn't show the root env
CONDA_ENVS+=" root"
TODAY=`date +%F`
HOUR=`date +%Hh%Mm`
SUBDIR_NAME=$TODAY/$HOUR
mkdir -p $SUBDIR_NAME
for ENV_NAME in $CONDA_ENVS
do
echo "Environment $ENV_NAME"
YML_NAME="${SUBDIR_NAME}/env_${ENV_NAME}_${TODAY}.yml"
conda env export -n $ENV_NAME > "${SUBDIR_NAME}/env_${ENV_NAME}_${TODAY}.yml"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment