DEV Community

Cover image for ☕️ Let's automate a backup process of your GitHub accounts, organizations & repositories
Vic Shóstak
Vic Shóstak

Posted on • Updated on

☕️ Let's automate a backup process of your GitHub accounts, organizations & repositories


Good day/night, DEV people! 😉 I declare openly: GitHub is my favorite professional social network to communicate and share my experience with other developers around the World.

But sometimes, when servers crash (which have increased dramatically in the last six months), I would like to have backups of all my projects on my work computer.

I'm talking about a full backup with all history, commits, pull-requests and releases of GitHub repository... not a simple git clone command!

So, what do I need to start backing up my GitHub account?

Let's work it out together! 👍

📝 Table of contents

The problem

If you've never seen GitHub Status page, I'm very happy for you! Because, it means I caught Internal Server Error (500), while working with GitHub... 😨

All the useful information, like "what's broken" or "when it's fixed", will be on this page. Also, you can subscribe to official Twitter account.

github status page

Yes, we spend thousands of hours (a la money) to write, support and improve projects. But let's not forget that the project doesn't really belong to us 100 percent, if it was uploaded to commercial service.

💭 GitHub is a commercial service for working with git (which also belongs to Microsoft Corporation), even if it has free plans.

Any downtime or rollback of such commercial service, can play a bad joke on you. Therefore, it's a good reason to have a full backup of all your projects. And on the whole, the backup hasn't bothered anyone yet!

↑ Table of contents


  • Install Python (3.5 and later) and Ansible (2.9 and later):
brew install python3 ansible
Enter fullscreen mode Exit fullscreen mode

☝️ This is example for macOS using the Brew package manager. How to install Python and Ansible on your system, please ask Google.

  • Download (or git clone) the Useful Ansible playbooks collection and go into its folder:
git clone

cd useful-playbooks
Enter fullscreen mode Exit fullscreen mode

GitHub logo truewebartisans / useful-playbooks

🚚 Useful Ansible playbooks for easily deploy your website or webapp to absolutely fresh remote virtual server and automation many processes. Only 3 minutes from the playbook run to complete setup server and start it.

  • Go to your GitHub settings and generate a new personal access token with needed scopes.

github personal access token

  • Create .env file with the following structure:
# GitHub users or organizations login names, 
# separated with commas (without spaces).

# GitHub personal access token.

# Max count of a saved backup files.

# Time to delay.
# - d: days
# - h: hours
# - m: minutes
# - s: seconds

# Timezone for DELAY_TIME.
# See:
Enter fullscreen mode Exit fullscreen mode

☝️ This is required, because the Docker image, what we're using in this playbook (koddr/github-backup-automation), rest on these environment variables.

  • Create a new virtual server with a pre-installed Docker (on DigitalOcean, for example, or on your favorite cloud provider. The minimum droplet's plan for $5/month, should be more than enough).

  • And, finally, run Ansible playbook:

ansible-playbook \
                  github_backup-playbook.yml \
                  --user <USER> \
                  --extra-vars "host=<HOST>"
Enter fullscreen mode Exit fullscreen mode

<USER> remote user's username (for example, root)
<HOST> hostname in your inventory (from /etc/ansible/hosts file)

All saved backups will be located at /var/github-backup folder of your remote server. That's it! 🎉

↑ Table of contents

Photos by


If you want more articles like this on this blog, then post a comment below and subscribe to me. Thanks! 😘

And, of course, you can support me by donating at LiberaPay. Each donation will be used to write new articles and develop non-profit open-source projects for the community.

Support author at LiberaPay

Discussion (2)

lifelongthinker profile image

Nice article, Vic. Thank you so much for sharing.
In fact, I have only recently been looking for an automated backup solution. But instead of running my own server (which is a perfectly valid choice, I just don't want to bother with yet another server), I'd like to use GitHub Actions to sync repos to another (SaaS) server upon commits, etc. What's your take on this?

koddr profile image
Vic Shóstak Author

Hi! Thanks for reply 👍

Yes, I think you can automate this process every commit through GitHub Actions. For example, you could use the same Docker image to create a container (or origin Python package), but then upload the resulting backup file, for example, via SSH to your SaaS server.

I use this action for SSH upload (but you can found or write your own 😉):