On Fri, 17 Aug 2012 01:52:54 -0700 (PDT)
Michal Idziorek <idzio...@gmail.com> wrote:

> What would be the most elegant way to fully backup a bare git
> repository. 
> Would the following approach work fine?
> tar -cf repository.tar repository/
> I wonder what happens if the repository is accessed during the backup?
Bad things happen: a Git repository is a collection of files, so any
transation semantics are implemented using some sort of policy *by the
Git tools* (supposedly through the usage of lock files).
Hence the only sure way to back up a Git repository which is
"online" (can be accessed by Git clients for pushing any time) is to
use Git tools.

In my shop, we back up each Git repo on the main server to its mirror
bare repository on another box using a call to `git fetch`:

git fetch --quiet --prune <repo> '+refs/*:refs/*'

which essentially means "bring everything the remote has, update
matching local things (overwrite, if necessary), then delete everything
the remote does not have anymore".

(In fact, the solution is more involved: we host our repos using
gitolite, and the backup script first fetches the list of repos it has
the read permissions for (nice feature of gitolite), then fetches from
each readable repo, initializing an appropriate local bare repo first,
if the remote repo is seen for the first time.)

Obviously, this backs the repositories up using another host and a
local network.  If you want to back up locally, there are at least two
solutions involving Git tools:
1) You can do the same fetching shown above, just using
   /path/to/the/repo or file:///path/to/the/repo
   URLs to specify the repository to back up.
2) Use `git bundle` which is essentially just a much smarter `tar -cf`
   with an added bonus that Git tools consider a bundle as a
   self-contained repository.

Yet another approach might be to just reverse the logic and move to
"push" approach for backups rather than "pull": for instance, recent
versions of gitolite grown built-in mirroring support [1].  

1. http://sitaramc.github.com/gitolite/mirroring.html

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to