Skip to content

Instantly share code, notes, and snippets.

@dmdeller
Created February 17, 2010 17:49
Show Gist options
  • Save dmdeller/306850 to your computer and use it in GitHub Desktop.
Save dmdeller/306850 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# config
date=`date "+%Y-%m-%d"`
git_binary=/usr/local/bin/git
# repositories in /git, space-separated.
repos="foo.git bar.git"
# back up repositories
cd /git
for repo in $repos
do
tar -czf /git/backup/${repo}-${date}.tar.gz ${repo}
done
# garbage-collect; reclaim disk space and optimize for performance
#
# NOTE: there is a GOOD REASON we do this AFTER backing up:
# if you accidentally deleted a branch or something, there might still be traces of it left before garbage-collecting.
# after running 'git gc', those traces are gone forever.
for repo in $repos
do
cd /git/${repo} && $git_binary gc --quiet
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment