Some python code to assist in migrating from one Forgejo server to another in bulk.
Find a file
2025-12-02 19:33:06 -08:00
.gitignore initial commit of files 2025-11-24 19:56:09 -08:00
LICENSE Initial commit 2025-11-24 18:04:36 -08:00
main.py moar try 2025-11-24 20:06:38 -08:00
Pipfile initial commit of files 2025-11-24 19:56:09 -08:00
README.md added mirror info to README 2025-12-02 19:32:41 -08:00

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+
  • pyforgejo library

Installation

  1. Clone this repository
  2. 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

  1. Update the repos_to_migrate list in main.py with 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
]
  1. Run the migration script:
    python main.py
    

How It Works

  1. The script loads required environment variables
  2. 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.