Some python code to assist in migrating from one Forgejo server to another in bulk.
|
|
||
|---|---|---|
| .gitignore | ||
| LICENSE | ||
| main.py | ||
| Pipfile | ||
| README.md | ||
Forgejo Migration Assistant
A simple tool to migrate repositories from one Forgejo instance to another, with automatic archiving of source repositories upon successful migration.
Overview
This tool automates the process of migrating repositories from a source Forgejo instance to a destination Forgejo instance. It handles:
- Repository migration using the Forgejo API
- Automatic archiving of source repositories upon successful migration
- Cleanup of destination repositories if migration fails
- Error handling and logging via print statements
NOTE: This repo is mirrored to https://codeberg.org/prasket/forgejo_migration_assistant
Features
- Automated Migration: Migrates repositories from source to destination Forgejo instance
- Source Archiving: Automatically archives source repositories after successful migration
- Error Recovery: Cleans up destination repositories if migration fails
- Simple Configuration: Uses environment variables for configuration
- Repository Management: Checks for existing repositories to avoid conflicts
Requirements
- Python 3.13+
pyforgejolibrary
Installation
- Clone this repository
- Install dependencies:
pip install -r requirements.txt # or if using pipenv pipenv install
Configuration
Create a .env file in the project root with the following variables:
REPO_OWNER="the-repository-owner"
SOURCE_URL="https://your-source-forgejo.com"
SOURCE_API_TOKEN="your-source-api-token"
DESTINATION_URL="https://your-destination-forgejo.com"
DESTINATION_API_TOKEN="your-destionation-api-token"
Usage
- Update the
repos_to_migratelist inmain.pywith the names of repositories you want to migrate:
repos_to_migrate: List[str] = [
"repo-name-1",
"repo-name-2",
# Add more repository names as needed
]
- Run the migration script:
python main.py
How It Works
- The script loads required environment variables
- For each repository in the migration list:
- Checks if the repository already exists in the destination
- Migrates the repository from the source
- On successful migration, archives the source repository
Error Handling
The tool includes error handling for:
- Repository migration failures
- Source archiving failures
- Destination cleanup failures
All status information is printed to stdout.
To Do
- Replace inline list of repo's to migrate with either env list or maybe txt file
- Maybe full logging ¯_(ツ)_/¯
License
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.