Skip to content

Instantly share code, notes, and snippets.

@surajmandalcell
Last active June 5, 2022 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surajmandalcell/f703f1fc7ad7c8f3eb2d98aaf50a9506 to your computer and use it in GitHub Desktop.
Save surajmandalcell/f703f1fc7ad7c8f3eb2d98aaf50a9506 to your computer and use it in GitHub Desktop.
If you maintain your repositories in a single folder grouped by org or such this backs them up, not the most efficient
# Variables
filename='.env-list.txt'
backupdir='~/Documents/backups__/envfiles'
rm -rf $filename
find . -name '*.env' >> $filename
while IFS="" read -r p || [ -n "$p" ]
do
if [[ "._" == *"$p"* ]]; then
echo "Skipping $p"
continue
fi
filename=$(basename "$p")
dirname=$(dirname -- "$p")
cleandirname=${dirname:2}
replacespaces=${cleandirname// /_}
replaceslashes=${replacespaces//\//_}
mkdir -p "$backupdir/$replaceslashes"
cp -R "$p" "$backupdir/$replaceslashes/$filename"
done < $filename
echo "Completed Backing Up .env Files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment