From 65a242c7cb81376719b1d1bbe83665b2c1e8cb72 Mon Sep 17 00:00:00 2001 From: tengel Date: Wed, 20 Mar 2024 11:55:04 -0500 Subject: [PATCH] adding Gitea Mirror --- Gitea-Mirror.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ _Sidebar.md | 1 + 2 files changed, 74 insertions(+) create mode 100644 Gitea-Mirror.md diff --git a/Gitea-Mirror.md b/Gitea-Mirror.md new file mode 100644 index 0000000..b07fb6f --- /dev/null +++ b/Gitea-Mirror.md @@ -0,0 +1,73 @@ +## Mission + +Mirror repositories from one Gitea instance to another, using a private SSH key from a 3rd workstation / server. This keeps the SSH private keypart secure on your own servers and allows for a password to be set on it as desired. + +## Setup + + 1. Create a new SSH keypair to use as a Deploy Key on both Gitea instances: + ``` + ssh-keygen -t ed25519 -a 100 -f reposync -C reposync + ``` + 2. Add the public keypart to the source repository as a Deploy Key without Write access + 3. Add the public keypart to the destination repository as a Deploy Key with Write access + 4. Disable Issues, Projects and Pull Requests on the destination repository (optional) + +Gitea allows the same SSH keypair to be used as Deploy Keys for multiple repositories. If using a password on the SSH keypair, leverage `ssh-agent` / `ssh-add` as needed. + +## Build Repos + +One-time need, prepare the initial repository sync setup and test the initial mirroring. + +**buildmirrors.sh** +``` +#!/usr/bin/env bash + +WDIR="${HOME}/repos/mirror" +cd "${WDIR}" || exit 1 + +REPOS="repo1 repo2 repo3 repo4" +USER="frank" +EMAIL="frank@thetank" +SSH="ssh -a -o IdentitiesOnly=yes -i ~/.ssh/reposync -F /dev/null" +SRC="git@src.gitea.server:frankthetank" +DST="git@dst.gitea.server:frankthetank" + +for repo in ${REPOS}; do + GIT_SSH_COMMAND="${SSH}" git clone --mirror ${SRC}/${repo}.git + if [[ -d ${repo}.git ]]; then + pushd "$(pwd)" >/dev/null + cd ${repo}.git + git config core.sshCommand "${SSH}" + git config user.name "${USER}" + git config user.email "${EMAIL}" + git remote set-url --push origin ${DST}/${repo}.git + git fetch -p origin + git push --mirror + popd >/dev/null + sleep 1 + fi +done +``` + +## Mirror Repos + +To be used to keep the repos mirrored over time, whether automated or manual. + +**repomirror.sh** +``` +#!/usr/bin/env bash + +WDIR="${HOME}/repos/mirror" +cd "${WDIR}" || exit 1 + +for repo in *.git/; do + if [[ -d "${repo}" && ! -L "${repo}" ]]; then + pushd "$(pwd)" >/dev/null + cd "${repo}" + git fetch -q -p origin + git push -q --mirror + popd >/dev/null + sleep 1 + fi +done +``` diff --git a/_Sidebar.md b/_Sidebar.md index 253e942..ef8fac7 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -20,6 +20,7 @@ - [[Git Quickstart]] - [[Git Rewrite User]] - [[Git Server]] +- [[Gitea Mirror]] - [[GitLab Anchors]] - [[Glibc IPv4]] - [[GnuPG Things]]