HOWTO backup Git repository

If you are paranoid (like me), you’d do a backup on everything. Data backup is OK, but structure is a b**** to protect & get up and running after a DR.

We run several Git repositories for several projects and while the data is triple-backed up, the git repo structure can be corrupted easily.

I did the following to create a single copy of each of our repo’s:

$ git clone --mirror ssh://git@hostname:port/<>
$ git bundle create <single-file.git>.bundle

To verify the file created is indeed correct:

$ git bundle verify <single-file.git>.bundle

To restore from this backup:

$ cd ${NEWDIR}
$ git clone <single-file.git>.bundle

To update your repo from the origin:

$ git remote update

This works well with a cronjob to update the mirror copy / update your single-file bundle.

You can alternatively also do a direct rsync-style synchronization across repo’s.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s