DEV Community

ak0047
ak0047

Posted on

Automatically Backing Up a GitHub Repository to S3 with GitHub Actions

Introduction

I built a GitHub Actions workflow that automatically backs up GitHub repositories to AWS S3.

The workflow is available as a template repository on GitHub:

👉 github-backup-template

Feel free to try it out if you’re interested!


Motivation

The idea came from this blog post I recently read:

🚀 Why You Should Keep Multiple Backups of Your Code (Don’t Rely Only on GitHub)

The author emphasized the importance of not relying solely on GitHub and keeping backups of your repositories. After reading it, I decided to set up my own backup system.

That article demonstrated how to automate local backups using cron or Task Scheduler. However, since my computer isn’t always running, I wanted a fully online, serverless approach. That’s when I thought:

“Why not leverage GitHub Actions’ scheduled workflows?”

So, I gave it a try.


How It Works

Workflow steps

  • Run on schedule with GitHub Actions
  • git clone --mirror the target repository
  • Create a bundle file
  • Upload the bundle to an S3 bucket

What gets backed up

  • Full commit history (all branches & tags)
  • Branch and tag references
  • Remote configuration & refs

What doesn’t get backed up

  • Issues / Pull Requests / Projects / Discussions / Actions history
  • Wiki or static files in GitHub Pages
  • Repository settings (e.g., Branch Protection rules)

Lessons Learned

A couple of tricky points during implementation:

awscli installation

Initially, I tried installing awscli in the workflow runner and ran into errors. Turns out it’s already pre-installed on GitHub-hosted runners—so no installation step was needed.

GitHub Personal Access Token authentication

I first tried with Fine-grained Personal Access Tokens, but authentication failed. Switching to a Classic Token with repo scope solved the issue.

Interestingly, GitHub Copilot was really helpful here—it suggested possible causes and fixes when my workflow runs failed.


Publishing the Template

After testing it on my own repositories and confirming the backups worked, I decided to publish it as a template repository.

My reasons:

  • Someone else might find it useful
  • It adds to my portfolio
  • It gives me something to blog about

In other words, three birds with one stone.

To make it easier for others to use, I:

  • Wrote all workflow comments in English
  • Provided a multi-language README (Japanese & English)
  • Added an MIT license for clarity

What’s Next

This project is still new, so I don’t have a detailed roadmap yet. But for now, my plans are:

  • Run it for my own repositories for a while
  • Collect user feedback
  • Consider S3 lifecycle policies (storage cost optimization, automated deletion, etc.)

If you have suggestions for improvement, I’d love to hear them!


Final Thoughts

This project started when reading an English blog post (as part of my language learning), which unexpectedly connected with something else I had learned earlier—GitHub Actions for automating React deployments.

It reminded me how valuable it is to keep gathering new inputs and ideas—you never know when they’ll connect.

Building this workflow was fun because I got to use GitHub Actions, GitHub Copilot, and AWS together.

I’m looking forward to making more small tools like this that might help others—while enjoying the process.

Top comments (0)