A lightweight Python-based CLI tool to automate the process of exporting GitHub Organization repositories. This tool fetches all repositories from a specific organization, initiates a migration, monitors its status, and downloads the final archive.
Sources used:
- https://docs.github.com/en/migrations/using-ghe-migrator/exporting-migration-data-from-githubcom#exporting-the-organizations-repositories
- https://docs.github.com/en/rest/migrations/orgs?apiVersion=2026-03-10
This code was made as a one-time use script. It was mostly written using Gemini in the interest of saving time in a time-constrained scenario. It been run and works.
- Automated Discovery: Fetches up to 100 repositories automatically from the target organization.
- Migration Management: Starts an authenticated migration with repository locking enabled.
- Status Tracking: Check the real-time status of your migration via the CLI.
- Secure Downloads: Streams the migration
.tar.gzarchive directly to your local machine once ready. - Secret Management: Uses
.envfiles to keep your GitHub Personal Access Token (PAT) secure.
- Python 3.7+
- GitHub Personal Access Token (PAT):
- For classic tokens, you need the
repoandadmin:orgscopes. - For fine-grained tokens, you need Organization Migrations (read/write) and Organization Metadata (read-only) permissions.
- For classic tokens, you need the
- Clone or save the script to your local machine.
- Install dependencies:
pip install requests python-dotenv
- Configure Environment Variables:
Create a
.envfile in the root directory:GITHUB_TOKEN=your_ghp_token_here GITHUB_ORG=chaoss
The tool is divided into three main commands: start, status, and download.
This command fetches all repositories in the org and triggers the GitHub migration engine.
uv run python3 backup.py start- Note: This script is configured to lock repositories (making them read-only) during the migration.
- Output: This will provide you with a Migration ID (e.g.,
54321). Save this ID.
GitHub needs time to package the data. Use the ID from the previous step to check progress.
uv run python3 backup.py status 54321- Wait until the status changes from
pendingorexportingtoexported.
Once the status is exported, download the final .tar.gz file.
uv run python3 backup.py download 54321- The file will be saved as
migration_ORG_ID.tar.gzin your current directory.
Once the download is complete, the repos that were locked for the migration need to be unlocked
uv run python3 backup.py unlock 54321- Archive Expiration: GitHub stores migration archives for 7 days. After that, they are deleted, and you must start a new migration.
- Pagination: This script currently fetches the first 100 repositories. If your organization has more, the script will need to be updated to handle API pagination loops.
- Rate Limits: Be mindful of GitHub API rate limits if running this repeatedly on very large organizations.
This project is licensed under the MIT License. Use it at your own risk—especially the lock_repositories feature!