Last active
October 15, 2018 10:39
-
-
Save kopiro/a413b3e148c16fd37a691361a6953aaf to your computer and use it in GitHub Desktop.
Backup all Repositories in current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
backup-repos() { | |
for i in $(find . -type d -maxdepth 1 -mindepth 1); do | |
echo "Looking in $i..." | |
if [ -d "$i/.git" ]; then | |
echo "Found repository in $i, init backup..." | |
pushd $i > /dev/null | |
zip_name="$i-$(date +'%y%m%d').zip" | |
zip_path="/opt/backups/$zip_name" | |
echo "ZIP path: $zip_path" | |
if [ ! -f "$zip_path" ]; then | |
echo "Backing up..." | |
git archive --format=zip --output="$zip_path" master | |
else | |
echo "ZIP $zip_path already exists, ignoring!" | |
fi | |
popd > /dev/null | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment