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
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.
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>'
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
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
{
"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/*"
]
}
]
}
Github migrations only archives your .git from every repository.
To recover your code from the archive:
- Place all the repo.git files in a .git folder.
- Execute the command
git init
- After Git has reinitialized the project, execute
git reset --hard HEAD
MIT / BSD
This Github Action was created in 2022 by Jeroen van der Meulen, commisioned by Skrepr