Skip to content

Instantly share code, notes, and snippets.

@antiops
Last active August 23, 2021 16:43
Show Gist options
  • Select an option

  • Save antiops/6f069e35bfe96a0a69cb2e92204f8ef1 to your computer and use it in GitHub Desktop.

Select an option

Save antiops/6f069e35bfe96a0a69cb2e92204f8ef1 to your computer and use it in GitHub Desktop.
Gitea: Change normal migrated repo to mirror mode

How to convert a migrated Gitea repository to a mirror

After looking around I couldn't find any place that had step by step instructions to do this. This will show you how to convert any migrated Gitea repo to a mirror repo. Only tested with gitHub repositories.

My use case: I migrated a GitHub repo and all of its issues/releases/etc with the API key option. When you create a fully cloned migration Gitea doesn't let you make it a mirror AFAIK. So you have to go digging through the Gitea database in order to change it to a mirror. And it does in fact work, you can migrate a remote repo in its entirety and thenchange it to mirror. Note: When you change to mirror, it will not mirror anything that requires an API key, it will just mirror the git repo.

For Gitea running with sqlite:

Open the Gitea database:

  • On default installations sqlite3 /opt/mailcow-dockerized/data/gitea/gitea/gitea.db
  • Or custom installation sqlite3 gitea.db in the gitea data directory wherever you installed it
Queries:
# Look for the repo you want to convert and ensure the last number is not 1
SELECT id,name,is_mirror from repository;

# Replace REPO_ID with the ID from above
UPDATE repository SET is_mirror='1' WHERE id=REPO_ID;

# This will look for the next available ID for us to add into the mirror table
SELECT id FROM mirror ORDER BY id DESC LIMIT 1;

# Get the number you got from above and add 1 to it (num + 1) and replace NEW_MIRROR_ID with it. Replace REPO_ID with the repo ID from the first step
INSERT INTO mirror VALUES(NEW_MIRROR_ID, REPO_ID, 28800000000000, 1, 0, 0);

For Gitea running with a different DB (PostgreSQL, MySQL, and MSSQL)

No instructions since I do not run those but I assume they are fairly similar, just some minor conversions to the syntax the database software uses.

Notes

  • Make backups :pepega:
  • Modify the queries to whatever database used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment