Skip to content
Powershell script and Docker image to backup an entire GitHub account including private repositories
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

GitHub Backup

Powershell script to back up all (public and private) repositories in a GitHub account. It can be run directly as script or a Docker image can be built by using the Dockerfile in the repo.


Personal access token

To be able to get a list of private repositories in your GitHub account you'd need a Personal Access Token. Generating one is quite straightforward:

  1. Go to this page:
  2. Tick repo checkbox so that token has access to private repositories
  3. Click Generate token button at the bottom of the page

SSH key

If you don't have already you'd need a SSH key that has been added to your GitHub account. You can follow this guide for that:

[Optional] Enable notifications (Email and/or AWS SNS)

You can choose to receive notifications via Email or let the script publish the result to an SNS topic you provide.

If you choose to receive notifications create the IAM accounts with required permissions and populate the config.json with those values. Make sure you set the enabled flag to true

"sns": {
    "enabled": false,
    "topicArn": "",
    "accessKey": "",
    "secretKey": "",
    "region": ""
"email": {
    "enabled": false,
    "fromEmailAddress": "",
    "toEmailAddress": "",
    "smtpHost": "",
    "smtpUsername": "",
    "smtpPassword": "",
    "smtpPort": 0


Powershell script uses AWS for notifications so first you should install AWS Tools for Powershell

Install-Module -Name AWSPowerShell.NetCore

By default the script uses config.json in the same folder but another file can be supplied by using the -ConfigPath parameter. Also by supplying -DryRun parameter you can test your GitHub access without actually cloning or pulling the repositories.

Basic usage:


Dry-run mode:

.\backup-github.ps1 -DryRun

Running with config in non-default path:

.\backup-github.ps1 -ConfigPath /Path/To/Config/ConfigName.json

Docker image

There's also a Docker image that contains the script. To run from Docker pull the image from Docker hub:

docker pull volkanx/github-backup

and start a container from the image:

docker run --rm -d -v /host/path/to/data:/home/gh-backup-data -v /host/path/to/config:/home/gh-backup-config -v ~/.ssh:/root/.ssh:ro volkanx/github-backup -ConfigPath /home/gh-backup-config/config.json

The command above runs the backup and deletes the container automatically.

The container doesn't have SSH keys so you have to mount a folder with your keys that have access to your GitHub account.

Build your own image

Open a terminal in the root of the repo

docker build . -t {image name}
You can’t perform that action at this time.