Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/skrepr/github-backup-action

Github Action to backup a Github Organization
https://github.com/skrepr/github-backup-action

action backup github typescript utility

Last synced: 4 days ago
JSON representation

Github Action to backup a Github Organization

Awesome Lists containing this project

README

        



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](https://docs.github.com/en/rest/migrations/orgs#start-an-organization-migration)

# 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](https://docs.github.com/en/[email protected]/articles/creating-an-access-token-for-command-line-use) 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:'`
# Github Action example config

## Create archive

```yaml
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

```yaml
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

```json
{
"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](https://github.com/jeroenvandermeulen), commisioned by [Skrepr](https://skrepr.com)