Mirror Tea

Mirror Tea
Photo by Markus Spiske

https://github.com/0xC9C3/mirror-tea

I wanted to mirror all my repositories from GitHub to a gitea instance. I found a few tools that do this, but they were either not maintained anymore or not working as expected. So I decided to write my own. The gitea instance is then backed up to my NAS. You can read more about my backup strategy here.

While it is possible to manually mirror all repositories, this is not very convenient. This tool automates the process.

Dependencies

To communicate with the gitea instance, the application uses the gitea api. There are a few crates available for this, but I decided to generate my own using the openapi generator, because most of them are not up-to-date. You can the gitea-rs repository here. The crate still has a few issues using the latest version of the gitea schema, since for example only HTTP Basic Auth is currently supported, because the usage of the identifier "apiKey" for 5 different authentication methods breaks the generator. Also, the crate should be automatically updated using the openapi generator, when a new version of the gitea schema is released.

For the communication to GitHub we use octocrab, since it is rather actively maintained and has a nice API.

To parse the input parameters, we use clap. To parse the config file, we use serde_yaml. For more information, see the Cargo.toml file.

Inner workings

The basic concept consists of two parts: the sources and the targets. The sources are the places where the repositories are mirrored from. The targets are the places where the repositories are mirrored to. Currently only GitHub and gitea are supported as sources and targets.

The application is designed to be run periodically. It will check all repositories of the configured sources and mirror them to the configured targets if they are not already mirrored.

The watcher_interval_ms is the interval in which the application checks for new repositories.

You can check the readme for the details of the sources and target configuration.

Also: The image is available on dockerhub and "weighs" only 7.77 MB! You can use the docker-compose.yml inside the repostiory as a template if you want to check it out.

Closing thoughts

While the tool does need some refactoring, it works for me and unless I have the need for more targets or sources I am probably not going to work much on it.

Automatically updating gitea-rs, mirror tea and publishing it to crates.io and dockerhub is on my todo list.

Thanks for reading and I hope you found it useful.