Skip to content

Instantly share code, notes, and snippets.

@kopiro
Last active October 15, 2018 10:39
Show Gist options
  • Save kopiro/a413b3e148c16fd37a691361a6953aaf to your computer and use it in GitHub Desktop.
Save kopiro/a413b3e148c16fd37a691361a6953aaf to your computer and use it in GitHub Desktop.
Backup all Repositories in current directory
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