Mathieu Larose

Back Up Your Git Repositories to S3 or Any S3-Compatible Storage

June 2024

I've been searching for a tool to back up my Git repositories to S3. Ideally, I wanted something that met the following criteria:

Unfortunately, none of the existing solutions seemed to offer everything I needed. So, I created an open-source tool called git-backup, specifically for developers who value these same criteria.

If these requirements match your Git backup needs, git-backup might be exactly what you're looking for.

For a live example, check out this GitHub workflow. It demonstrates how I use git-backup and GitHub Actions to back up my public GitHub repositories to CloudFlare R2. This setup takes a snapshot every month and retains the three most recent monthly snapshots for each repository.

Importantly, git-backup can also be used independently of GitHub Actions.

git-backup

git-backup has two commands:

I won't repeat the entire documentation here, as the git-backup manual covers everything in detail. However, I'll discuss the essential pieces.

Here's an example of how to back up the repo github.com:larose/utt to CloudFlare R2:

$ git-backup snapshot \
  --repo git@github.com:larose/utt.git \
  --remote https://123.r2.cloudflarestorage.com/bucket-name \
  --access-key-id AKIAIOSFODNN7EXAMPLE \
  --secret-access-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Be sure to replace the values of --remote, --access-key-id, and --secret-access-key with your own credentials.

Similarly, here's an example of how to prune old snapshots:

$ git-backup prune \
  --repo git@github.com:larose/utt.git \
  --remote https://123.r2.cloudflarestorage.com/bucket/base/path \
  --retention-policy "daily=7, weekly=4, monthly=3" \
  --access-key-id AKIAIOSFODNN7EXAMPLE \
  --secret-access-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

This command retains the 7 most recent daily snapshots, the 4 most recent weekly snapshots, and the 3 most recent monthly snapshots.

I encourage you to visit the git-backup manual to learn more about the tool.

Like this article? Get notified of new ones: