Files
infrastructure/clusters/cl01tl/manifests/gitea/CronJob-gitea-backup.yml

132 lines
4.7 KiB
YAML

---
# Source: gitea/charts/backup/templates/common.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: gitea-backup
labels:
app.kubernetes.io/controller: backup
app.kubernetes.io/instance: gitea
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: gitea
helm.sh/chart: backup-4.4.0
namespace: gitea
spec:
suspend: false
concurrencyPolicy: Forbid
startingDeadlineSeconds: 90
timeZone: US/Central
schedule: "0 4 */2 * *"
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
jobTemplate:
spec:
parallelism: 1
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/controller: backup
app.kubernetes.io/instance: gitea
app.kubernetes.io/name: gitea
spec:
enableServiceLinks: false
serviceAccountName: gitea-backup
automountServiceAccountToken: true
hostIPC: false
hostNetwork: false
hostPID: false
dnsPolicy: ClusterFirst
restartPolicy: Never
initContainers:
- args:
- -ec
- |
kubectl exec -it deploy/gitea -n gitea -- rm -f /opt/backup/gitea-backup.zip;
kubectl exec -it deploy/gitea -n gitea -- /app/gitea/gitea dump -c /data/gitea/conf/app.ini --file /opt/backup/gitea-backup.zip;
command:
- sh
image: bitnami/kubectl:latest
imagePullPolicy: IfNotPresent
name: backup
resources:
requests:
cpu: 100m
memory: 128Mi
containers:
- args:
- -ec
- |
echo ">> Running S3 backup for Gitea"
s3cmd put --no-check-md5 --no-check-certificate -v /opt/backup/gitea-backup.zip ${BUCKET}/cl01tl/gitea-backup-$(date +"%Y%m%d-%H-%M").zip;
mv /opt/backup/gitea-backup.zip /opt/backup/gitea-backup-$(date +"%Y%m%d-%H-%M").zip;
echo ">> Completed S3 backup for Gitea"
command:
- /bin/sh
env:
- name: BUCKET
valueFrom:
secretKeyRef:
key: BUCKET
name: gitea-s3cmd-config
image: d3fk/s3cmd:latest@sha256:590c42746db1252be8aad33e287c7910698c32b58b4fc34f67592a5bd0841551
imagePullPolicy: IfNotPresent
name: s3-backup
resources:
requests:
cpu: 100m
memory: 128Mi
volumeMounts:
- mountPath: /opt/backup
name: config
- mountPath: /root/.s3cfg
mountPropagation: None
name: s3cmd-config
readOnly: true
subPath: .s3cfg
- args:
- -ec
- |
export DATE_RANGE=$(date -d @$(( $(date +%s) - 604800 )) +%Y%m%d);
export FILE_MATCH="$BUCKET/cl01tl/gitea-backup-$DATE_RANGE-09-00.zip"
echo ">> Running S3 prune for Gitea backup repository"
echo ">> Backups prior to '$DATE_RANGE' will be removed"
echo ">> Backups to be removed:"
s3cmd ls ${BUCKET}/cl01tl/ |
awk -v file_match="$FILE_MATCH" '$4 < file_match {print $4}'
echo ">> Deleting ..."
s3cmd ls ${BUCKET}/cl01tl/ |
awk -v file_match="$FILE_MATCH" '$4 < file_match {print $4}' |
while read file; do
s3cmd del "$file";
done;
echo ">> Completed S3 prune for Gitea backup repository"
command:
- /bin/sh
env:
- name: BUCKET
valueFrom:
secretKeyRef:
key: BUCKET
name: gitea-s3cmd-config
image: d3fk/s3cmd:latest@sha256:590c42746db1252be8aad33e287c7910698c32b58b4fc34f67592a5bd0841551
imagePullPolicy: IfNotPresent
name: s3-prune
resources:
requests:
cpu: 100m
memory: 128Mi
volumeMounts:
- mountPath: /root/.s3cfg
mountPropagation: None
name: s3cmd-config
readOnly: true
subPath: .s3cfg
volumes:
- name: config
persistentVolumeClaim:
claimName: gitea-nfs-storage-backup
- name: s3cmd-config
secret:
secretName: gitea-s3cmd-config