adding Gitea Mirror

tengel 2024-03-20 11:55:04 -05:00
parent c6b5700a0e
commit 65a242c7cb
2 changed files with 74 additions and 0 deletions

73
Gitea-Mirror.md Normal file

@ -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
```

@ -20,6 +20,7 @@
- [[Git Quickstart]]
- [[Git Rewrite User]]
- [[Git Server]]
- [[Gitea Mirror]]
- [[GitLab Anchors]]
- [[Glibc IPv4]]
- [[GnuPG Things]]