mirror of
https://github.com/auricom/home-cluster.git
synced 2025-09-17 18:24:14 +02:00
86 lines
3.4 KiB
YAML
86 lines
3.4 KiB
YAML
---
|
|
apiVersion: batch/v1
|
|
kind: CronJob
|
|
metadata:
|
|
name: gitea-repositories-backup
|
|
namespace: development
|
|
spec:
|
|
schedule: "@daily"
|
|
jobTemplate:
|
|
spec:
|
|
template:
|
|
metadata:
|
|
name: gitea-repositories-backup
|
|
spec:
|
|
serviceAccountName: jobs
|
|
imagePullSecrets:
|
|
- name: regcred
|
|
containers:
|
|
- name: gitea-repositories-backup
|
|
image: registry.${SECRET_CLUSTER_DOMAIN}/homelab/home-cluster-jobs:1.1.0
|
|
imagePullPolicy: IfNotPresent
|
|
command:
|
|
- "bin/sh"
|
|
- "-ec"
|
|
- |
|
|
#!/bin/bash
|
|
|
|
set -o nounset
|
|
set -o errexit
|
|
|
|
mkdir -p ~/.ssh
|
|
cp /opt/id_rsa ~/.ssh/id_rsa
|
|
chmod 600 ~/.ssh/id_rsa
|
|
|
|
ssh -o StrictHostKeyChecking=no homelab@${LOCAL_LAN_TRUENAS} << 'EOF'
|
|
|
|
WORK_DIR="/mnt/storage/backups/gitea"
|
|
|
|
ORGANISATIONS=$(curl --silent --location --request GET "https://gitea.${SECRET_CLUSTER_DOMAIN}/api/v1/orgs" --header "Authorization: Bearer ${SECRET_GITEA_API_TOKEN}" | jq --raw-output .[].username)
|
|
ORGANISATIONS+=" auricom"
|
|
|
|
for org in $ORGANISATIONS
|
|
do
|
|
mkdir -p $WORK_DIR/$org
|
|
if [ $org == "auricom" ]; then
|
|
keyword="users"
|
|
else
|
|
keyword="orgs"
|
|
fi
|
|
REPOSITORIES=$(curl --silent --location --request GET "https://gitea.${SECRET_CLUSTER_DOMAIN}/api/v1/$keyword/$org/repos?limit=1000" --header "Authorization: Bearer ${SECRET_GITEA_API_TOKEN}" | jq --raw-output .[].name)
|
|
for repo in $REPOSITORIES
|
|
do
|
|
if [ -d "$WORK_DIR/$org/$repo" ]; then
|
|
echo "INFO: pull $org/$repo..."
|
|
cd $WORK_DIR/$org/$repo
|
|
git reset --hard
|
|
git pull
|
|
test $? -ne 0 && exit 1
|
|
echo "INFO: clean $org/$repo..."
|
|
git fetch --prune
|
|
for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}')
|
|
do
|
|
git branch -D $branch
|
|
done
|
|
else
|
|
echo "INFO: clone $org/$repo..."
|
|
cd $WORK_DIR/$org
|
|
git clone git@gitea.${SECRET_CLUSTER_DOMAIN_ROOT}:$org/$repo.git
|
|
test $? -ne 0 && exit 1
|
|
fi
|
|
done
|
|
done
|
|
echo "INFO: Backup done"
|
|
EOF
|
|
|
|
curl -m 10 --retry 5 http://healthchecks.monitoring.svc.cluster.local.:8000/ping/f7ff2516-e3b5-41ae-b77f-a9dc09005422
|
|
volumeMounts:
|
|
- name: secret
|
|
mountPath: /opt/id_rsa
|
|
subPath: deployment-rsa-priv-key
|
|
volumes:
|
|
- name: secret
|
|
secret:
|
|
secretName: drone-pipelines
|
|
restartPolicy: Never
|