Skip to content
upload-cloud

GitHub Action

Github Migrations Backup

2.0.1 Latest version

Github Migrations Backup

upload-cloud

Github Migrations Backup

Backup a Github Org with one Action

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Github Migrations Backup

uses: skrepr/[email protected]

Learn more about this action in skrepr/github-backup-action

Choose a version

skrepr_logo

Github Backup Action

Releases LICENSE Issues PR Commits Stars Forks

About

This GitHub Action allows you to backup and archive a organization repository to an S3 Bucket with the help of the GitHub Organization migrations API

Requirements

The Migrations API is only available to authenticated organization owners. For more information, see "Roles in an organization" and "Other authentication methods."

Ensure that you have owner permissions on the source organization's repositories. Generate an access token with the repo and admin:org scopes on GitHub.com. To minimize downtime, make a list of repositories you want to export from the source instance. You can add multiple repositories to an export at once using a text file that lists the URL of each repository on a separate line.

Commands

To build the project: npm run build To watch project during developement: npm run watch To run the script: node dist/main.ts List all repos: curl "https://api.github.com/orgs/skrepr/repos" \ -u 'username:<personal access token>'

Github Action example config

Create archive

name: Backup repositories

on:
  schedule:
    - cron: '0 1 * * 0'  # At 01:00 on Sunday

jobs:
  backup:
    name: Create archive
    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:
    - name: Github Migrations Backup
      uses: skrepr/[email protected]
      with:
        github-organization: "your-organization-here"
        github-apikey: ${}
        aws-bucket-name: "your-bucket-here"
        aws-bucket-region: "your-bucket-region-here"
        aws-access-key: ${AWS_ACCESS_KEY} # Github Secret is advised
        aws-secret-key: ${AWS_SECRET_KEY} # Github Secret is advised

    # Save migration.data.id as an artifact at the end of the first run
    - name: Archive Data
      uses: actions/upload-artifact@v2
      with:
        name: migration-data
        path: migration_response.json

Download archive

name: Download archive

on:
  schedule:
    - cron: '0 3 * * 0'  # At 03:00 on Sunday

jobs:
  backup:
    name: Download archive
    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:

    # Download the migration.data.id as an artifact at the beginning of the second run
    - name: Archive Data
      uses: actions/download-artifact@v2
      with:
        name: migration-data
        path: migration_response.json

    - name: Github Migrations Backup
      uses: skrepr/[email protected]
      with:
        download-migration: true
        github-organization: "your-organization-here"
        github-apikey: ${}
        aws-bucket-name: "your-bucket-here"
        aws-bucket-region: "your-bucket-region-here"
        aws-access-key: ${AWS_ACCESS_KEY} # Github Secret is advised
        aws-secret-key: ${AWS_SECRET_KEY} # Github Secret is advised

AWS policy for S3 bucket user

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::your-bucket-here"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::your-bucket-here/*"
            ]
        }
    ]
}

Recovering your repositories from the archive

Github migrations only archives your .git from every repository.

To recover your code from the archive:

  1. Place all the repo.git files in a .git folder.
  2. Execute the command git init
  3. After Git has reinitialized the project, execute git reset --hard HEAD

License

MIT / BSD

Author Information

This Github Action was created in 2022 by Jeroen van der Meulen, commisioned by Skrepr