feat(homelab): setup mc-backup, add restore job, change gitea host

This commit is contained in:
2025-12-26 23:37:40 -08:00
parent 4771603175
commit 98124678c3
6 changed files with 228 additions and 72 deletions

View File

@@ -56,19 +56,19 @@ releases:
defaultClassReplicaCount: 1 defaultClassReplicaCount: 1
# Minecraft # Minecraft
# - name: minecraft-router - name: minecraft-router
# namespace: minecraft namespace: minecraft
# chart: minecraft-charts/mc-router chart: minecraft-charts/mc-router
# version: 1.4.0 version: 1.4.0
# values: values:
# - values/minecraft/router.yaml - values/minecraft/router.yaml
#
# - name: minecraft-main - name: minecraft-main
# namespace: minecraft namespace: minecraft
# chart: minecraft-charts/minecraft chart: minecraft-charts/minecraft
# version: 5.0.0 version: 5.0.0
# values: values:
# - values/minecraft/main.yaml - values/minecraft/main.yaml
- name: home-assistant - name: home-assistant
namespace: home namespace: home

View File

@@ -13,66 +13,105 @@ minecraftServer:
difficulty: hard difficulty: hard
motd: "A Minecraft Server." motd: "A Minecraft Server."
memory: 6G memory: 6G
rcon:
enabled: true
withGeneratedPassword: false
port: 25575
existingSecret: rcon-credentials
secretKey: rcon-password
persistence: persistence:
dataDir: dataDir:
enabled: true enabled: true
Size: 4Gi Size: 4Gi
# extraVolumes: sidecarContainers:
# - volumeMounts: - name: backup
# - name: backup-volume image: itzg/mc-backup
# mountPath: /backup imagePullPolicy: Always
# readOnly: true env:
# volumes: - name: RCON_PASSWORD
# - name: backup-volume valueFrom:
# hostPath: secretKeyRef:
# path: /var/lib/minecraft name: rcon-credentials
# type: DirectoryOrCreate key: rcon-password
- name: BACKUP_METHOD
value: tar
- name: BACKUP_INTERVAL
value: "15m"
- name: INITIAL_DELAY
value: "5m"
- name: PRUNE_BACKUPS_COUNT
value: "15"
- name: DEST_DIR
value: /mnt/backups
- name: LINK_LATEST
value: "true"
- name: TAR_COMPRESS_METHOD
value: gzip
- name: BACKUP_NAME
value: minecraft-main
- name: TZ
value: "America/Vancouver"
volumeMounts:
- name: datadir
mountPath: /data
readOnly: true
- name: backups
mountPath: /mnt/backups
# initContainers: extraVolumes:
# - name: world-restore - volumeMounts:
# image: busybox:latest - name: backups
# command: mountPath: /mnt/backups
# - sh volumes:
# - -c - name: backups
# - | nfs:
# set -e server: 192.168.27.2
# path: /backup/minecraft
# echo "=== Minecraft World Restore ==="
# initContainers:
# BACKUP_FILE="/backup/main/latest.tar.gz" - name: world-restore
# image: busybox:latest
# # Check if backup exists command:
# if [ ! -f "$BACKUP_FILE" ]; then - sh
# echo "No backup found at $BACKUP_FILE" - -c
# echo "Skipping restore, server will start with existing/new world" - |
# exit 0 set -e
# fi
# echo "=== Minecraft World Restore ==="
# echo "✓ Backup found: $BACKUP_FILE"
# echo " Size: $(du -h $BACKUP_FILE | cut -f1)" BACKUP_FILE="/backups/latest.tgz"
#
# # Check if world already exists # Check if backup exists
# if [ -f /data/world/level.dat ]; then if [[ ! -f "$BACKUP_FILE" ]]; then
# echo "⚠ World already exists at /data/world/" echo "Skipping restore, server will start with existing/new world"
# echo " Replacing with backup..." exit 0
# rm -rf /data/world /data/world_nether /data/world_the_end fi
# fi
# echo "✓ Backup found: $BACKUP_FILE"
# # Extract backup echo " Size: $(du -h $BACKUP_FILE | cut -f1)"
# echo "Extracting backup to /data/..."
# tar -xzf "$BACKUP_FILE" -C /data/ # Check if world already exists
# echo "✓ Extraction complete" if [ -f /data/world/level.dat ]; then
# echo "⚠ World already exists at /data/world/"
# echo "" echo " Replacing with backup..."
# echo "=== Restore Complete ===" rm -rf /data/world /data/world_nether /data/world_the_end
# echo "Restored world size: $(du -sh /data/world 2>/dev/null | cut -f1 || echo 'unknown')" fi
# ls -lh /data/ | grep -E "^d" || true
# echo "" # Extract backup
# volumeMounts: echo "Extracting backup to /data/..."
# - name: datadir tar -xzf "$BACKUP_FILE" -C /data/
# mountPath: /data echo "✓ Extraction complete"
# - name: backup-volume
# mountPath: /backup echo ""
# readOnly: true echo "=== Restore Complete ==="
echo "Restored world size: $(du -sh /data/world 2>/dev/null | cut -f1 || echo 'unknown')"
ls -lh /data/ | grep -E "^d" || true
echo ""
volumeMounts:
- name: datadir
mountPath: /data
- name: backup-volume
mountPath: /backup
readOnly: true

View File

@@ -6,7 +6,7 @@ resources:
- ./traefik/config.yaml - ./traefik/config.yaml
- ./cert-manager/config.yaml - ./cert-manager/config.yaml
- ./routes/media.yaml - ./routes/media.yaml
# - ./routes/minecraft.yaml - ./routes/minecraft.yaml
- ./routes/gitea/ssh.yaml - ./routes/gitea/ssh.yaml
- ./routes/gitea/http.yaml - ./routes/gitea/http.yaml
- ./routes/longhorn.yaml - ./routes/longhorn.yaml

View File

@@ -0,0 +1,117 @@
apiVersion: batch/v1
kind: Job
metadata:
name: minecraft-restore
namespace: minecraft
labels:
app: minecraft-restore
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 3600
template:
metadata:
labels:
app: minecraft-restore
spec:
restartPolicy: Never
securityContext:
fsGroup: 2000
runAsUser: 1000
runAsGroup: 3000
containers:
- name: restore
image: busybox:latest
command:
- sh
- -c
- |
set -e
echo "=========================================="
echo "Minecraft World Restore Job"
echo "=========================================="
echo ""
SERVER_NAME="${SERVER_NAME}"
BACKUP_FILE="${BACKUP_FILE:-latest.tgz}"
BACKUP_PATH="/backups/${BACKUP_FILE}"
DATA_DIR="/data"
echo "Configuration:"
echo " Server: ${SERVER_NAME}"
echo " Backup file: ${BACKUP_FILE}"
echo " Backup path: ${BACKUP_PATH}"
echo " Data directory: ${DATA_DIR}"
echo ""
if [ ! -f "${BACKUP_PATH}" ]; then
echo "ERROR: Backup file not found: ${BACKUP_PATH}"
echo ""
echo "Available backups for ${SERVER_NAME}:"
ls -lh /backups/ | grep "minecraft-${SERVER_NAME}" || echo " (none found)"
echo ""
echo "All backups:"
ls -lh /backups/
exit 1
fi
echo "✓ Backup file found"
echo " Size: $(du -hL ${BACKUP_PATH} | cut -f1)"
echo ""
if [ -d "${DATA_DIR}/world" ]; then
echo "⚠ WARNING: Existing world data found!"
echo " The following directories will be removed:"
echo " - ${DATA_DIR}/world"
echo " - ${DATA_DIR}/world_nether"
echo " - ${DATA_DIR}/world_the_end"
echo ""
echo "Removing existing world data..."
rm -rf "${DATA_DIR}/world" "${DATA_DIR}/world_nether" "${DATA_DIR}/world_the_end"
echo "✓ Old world data removed"
else
echo "✓ No existing world data found (clean slate)"
fi
echo ""
echo "Extracting backup..."
echo " From: ${BACKUP_PATH}"
echo " To: ${DATA_DIR}/"
echo ""
tar -xzf "${BACKUP_PATH}" -C "${DATA_DIR}/"
echo ""
echo "=========================================="
echo "Restore Complete!"
echo "=========================================="
echo ""
echo "Restored world information:"
if [ -d "${DATA_DIR}/world" ]; then
echo " World size: $(du -sh ${DATA_DIR}/world | cut -f1)"
fi
env:
- name: SERVER_NAME
value: "main"
- name: BACKUP_FILE
value: "latest.tgz"
volumeMounts:
- name: data
mountPath: /data
- name: backups
mountPath: /backups
readOnly: true
volumes:
- name: data
persistentVolumeClaim:
claimName: minecraft-main-datadir
- name: backups
nfs:
server: 192.168.27.2
path: /backup/minecraft

View File

@@ -8,7 +8,7 @@ spec:
- name: traefik-gateway - name: traefik-gateway
namespace: kube-system namespace: kube-system
hostnames: hostnames:
- "git-new.lucalise.ca" - "git.lucalise.ca"
rules: rules:
- backendRefs: - backendRefs:
- name: gitea-http - name: gitea-http

View File

@@ -20,7 +20,7 @@
networking.extraHosts = '' networking.extraHosts = ''
192.168.18.31 traefik.lucalise.ca 192.168.18.31 traefik.lucalise.ca
192.168.18.31 media.lucalise.ca 192.168.18.31 media.lucalise.ca
192.168.18.31 git-new.lucalise.ca 192.168.18.31 git.lucalise.ca
192.168.18.31 storage.lucalise.ca 192.168.18.31 storage.lucalise.ca
192.168.18.31 home-assistant.lucalise.ca 192.168.18.31 home-assistant.lucalise.ca
192.168.18.31 mc-rocket.duckdns.org 192.168.18.31 mc-rocket.duckdns.org