feat(homelab): setup mc-backup, add restore job, change gitea host
This commit is contained in:
@@ -56,19 +56,19 @@ releases:
|
||||
defaultClassReplicaCount: 1
|
||||
|
||||
# Minecraft
|
||||
# - name: minecraft-router
|
||||
# namespace: minecraft
|
||||
# chart: minecraft-charts/mc-router
|
||||
# version: 1.4.0
|
||||
# values:
|
||||
# - values/minecraft/router.yaml
|
||||
#
|
||||
# - name: minecraft-main
|
||||
# namespace: minecraft
|
||||
# chart: minecraft-charts/minecraft
|
||||
# version: 5.0.0
|
||||
# values:
|
||||
# - values/minecraft/main.yaml
|
||||
- name: minecraft-router
|
||||
namespace: minecraft
|
||||
chart: minecraft-charts/mc-router
|
||||
version: 1.4.0
|
||||
values:
|
||||
- values/minecraft/router.yaml
|
||||
|
||||
- name: minecraft-main
|
||||
namespace: minecraft
|
||||
chart: minecraft-charts/minecraft
|
||||
version: 5.0.0
|
||||
values:
|
||||
- values/minecraft/main.yaml
|
||||
|
||||
- name: home-assistant
|
||||
namespace: home
|
||||
|
||||
@@ -13,66 +13,105 @@ minecraftServer:
|
||||
difficulty: hard
|
||||
motd: "A Minecraft Server."
|
||||
memory: 6G
|
||||
rcon:
|
||||
enabled: true
|
||||
withGeneratedPassword: false
|
||||
port: 25575
|
||||
existingSecret: rcon-credentials
|
||||
secretKey: rcon-password
|
||||
|
||||
persistence:
|
||||
dataDir:
|
||||
enabled: true
|
||||
Size: 4Gi
|
||||
|
||||
# extraVolumes:
|
||||
# - volumeMounts:
|
||||
# - name: backup-volume
|
||||
# mountPath: /backup
|
||||
# readOnly: true
|
||||
# volumes:
|
||||
# - name: backup-volume
|
||||
# hostPath:
|
||||
# path: /var/lib/minecraft
|
||||
# type: DirectoryOrCreate
|
||||
sidecarContainers:
|
||||
- name: backup
|
||||
image: itzg/mc-backup
|
||||
imagePullPolicy: Always
|
||||
env:
|
||||
- name: RCON_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: rcon-credentials
|
||||
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:
|
||||
# - name: world-restore
|
||||
# image: busybox:latest
|
||||
# command:
|
||||
# - sh
|
||||
# - -c
|
||||
# - |
|
||||
# set -e
|
||||
#
|
||||
# echo "=== Minecraft World Restore ==="
|
||||
#
|
||||
# BACKUP_FILE="/backup/main/latest.tar.gz"
|
||||
#
|
||||
# # Check if backup exists
|
||||
# if [ ! -f "$BACKUP_FILE" ]; then
|
||||
# echo "No backup found at $BACKUP_FILE"
|
||||
# echo "Skipping restore, server will start with existing/new world"
|
||||
# exit 0
|
||||
# fi
|
||||
#
|
||||
# echo "✓ Backup found: $BACKUP_FILE"
|
||||
# echo " Size: $(du -h $BACKUP_FILE | cut -f1)"
|
||||
#
|
||||
# # Check if world already exists
|
||||
# if [ -f /data/world/level.dat ]; then
|
||||
# echo "⚠ World already exists at /data/world/"
|
||||
# echo " Replacing with backup..."
|
||||
# rm -rf /data/world /data/world_nether /data/world_the_end
|
||||
# fi
|
||||
#
|
||||
# # Extract backup
|
||||
# echo "Extracting backup to /data/..."
|
||||
# tar -xzf "$BACKUP_FILE" -C /data/
|
||||
# echo "✓ Extraction complete"
|
||||
#
|
||||
# echo ""
|
||||
# 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
|
||||
extraVolumes:
|
||||
- volumeMounts:
|
||||
- name: backups
|
||||
mountPath: /mnt/backups
|
||||
volumes:
|
||||
- name: backups
|
||||
nfs:
|
||||
server: 192.168.27.2
|
||||
path: /backup/minecraft
|
||||
|
||||
initContainers:
|
||||
- name: world-restore
|
||||
image: busybox:latest
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
set -e
|
||||
|
||||
echo "=== Minecraft World Restore ==="
|
||||
|
||||
BACKUP_FILE="/backups/latest.tgz"
|
||||
|
||||
# Check if backup exists
|
||||
if [[ ! -f "$BACKUP_FILE" ]]; then
|
||||
echo "Skipping restore, server will start with existing/new world"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "✓ Backup found: $BACKUP_FILE"
|
||||
echo " Size: $(du -h $BACKUP_FILE | cut -f1)"
|
||||
|
||||
# Check if world already exists
|
||||
if [ -f /data/world/level.dat ]; then
|
||||
echo "⚠ World already exists at /data/world/"
|
||||
echo " Replacing with backup..."
|
||||
rm -rf /data/world /data/world_nether /data/world_the_end
|
||||
fi
|
||||
|
||||
# Extract backup
|
||||
echo "Extracting backup to /data/..."
|
||||
tar -xzf "$BACKUP_FILE" -C /data/
|
||||
echo "✓ Extraction complete"
|
||||
|
||||
echo ""
|
||||
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
|
||||
|
||||
@@ -6,7 +6,7 @@ resources:
|
||||
- ./traefik/config.yaml
|
||||
- ./cert-manager/config.yaml
|
||||
- ./routes/media.yaml
|
||||
# - ./routes/minecraft.yaml
|
||||
- ./routes/minecraft.yaml
|
||||
- ./routes/gitea/ssh.yaml
|
||||
- ./routes/gitea/http.yaml
|
||||
- ./routes/longhorn.yaml
|
||||
|
||||
117
nix/homelab/kustomize/restore-job.yaml
Normal file
117
nix/homelab/kustomize/restore-job.yaml
Normal 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
|
||||
@@ -8,7 +8,7 @@ spec:
|
||||
- name: traefik-gateway
|
||||
namespace: kube-system
|
||||
hostnames:
|
||||
- "git-new.lucalise.ca"
|
||||
- "git.lucalise.ca"
|
||||
rules:
|
||||
- backendRefs:
|
||||
- name: gitea-http
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
networking.extraHosts = ''
|
||||
192.168.18.31 traefik.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 home-assistant.lucalise.ca
|
||||
192.168.18.31 mc-rocket.duckdns.org
|
||||
|
||||
Reference in New Issue
Block a user