Penta 7 hónapja
commit
fc6d6c84e3
3 módosított fájl, 84 hozzáadás és 0 törlés
  1. 11 0
      Dockerfile
  2. 37 0
      cronjob-backup-minecraft.yaml
  3. 36 0
      entrypoint.sh

+ 11 - 0
Dockerfile

@@ -0,0 +1,11 @@
+# Utilisez une image base de votre choix (ici, nous utilisons Ubuntu)
+FROM ubi8/ubi:latest
+
+# Copiez votre script bash dans le conteneur
+COPY entrypoint.sh /entrypoint.sh
+
+# Rendez le script exécutable
+RUN chown -R 0:0 /entrypoint.sh && chmod -R g+rwx /entrypoint.sh
+
+# Commande à exécuter quand le conteneur se lance (ici, elle est optionnelle)
+CMD ["/bin/bash", "-c", "/entrypoint.sh"]

+ 37 - 0
cronjob-backup-minecraft.yaml

@@ -0,0 +1,37 @@
+apiVersion: batch/v1
+kind: CronJob
+metadata:
+  name: backup-minecraft-world
+spec:
+  schedule: "30 2 * * *"
+  concurrencyPolicy: Forbid
+  jobTemplate:
+    spec:
+      template:
+        spec:
+          containers:
+          - name: backup-minecraft-world
+            image: registry.apps.openshift.local.pentou.ovh/penta/backup-job:1.0
+            env:
+            - name: BACKUP_DIR
+              value: "/backups"
+            - name: DIRECTORIES
+              value: "/minecraft/Maisonnette /minecraft/Maisonnette_nether /minecraft/Maisonnette_the_end /minecraft/Survival /minecraft/Survival_nether"
+            - name: RETENTION_DAYS
+              value: "14"
+            volumeMounts:
+              - name: mc-data
+                mountPath: "/minecraft"
+              - name: mc-backup
+                mountPath: "/backups"
+          restartPolicy:
+            OnFailure
+          volumes:
+            - name: mc-data
+              persistentVolumeClaim:
+                claimName: pvc-minecraft-server-data
+            - name: mc-backup
+              persistentVolumeClaim:
+                claimName: pvc-minecraft-backup
+  successfulJobsHistoryLimit: 3
+  failedJobsHistoryLimit: 1

+ 36 - 0
entrypoint.sh

@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Variables d'environnement
+BACKUP_DIR=${BACKUP_DIR:-"/backups"}
+DIRECTORIES=${DIRECTORIES:-"/source /source2"}
+RETENTION_DAYS=${RETENTION_DAYS:-14}
+
+# Array contenant les dossiers à sauvegarder (split des espaces)
+DIRECTORIES_ARRAY=($DIRECTORIES)
+
+# Création du dossier de backup s'il n'existe pas
+if [ ! -d "$BACKUP_DIR" ]; then
+    echo "ERROR: Backup directory does not exist!"
+    exit 1
+fi
+
+# Boucle pour chaque dossier dans l'array
+for dir in "${DIRECTORIES_ARRAY[@]}"; do
+    # Vérification si le dossier existe
+    if [ ! -d "$dir" ]; then
+        echo "WARNING: Source directory $dir does not exist."
+        continue
+    fi
+    
+    # Création du nom de fichier de backup avec la date
+    base_name=$(basename "$dir")
+    file_name="${BACKUP_DIR}/${base_name}_$(date +%Y%m%d).tar.gz"
+    
+    # Création du backup zip
+    tar -czf "$file_name" "$dir"
+    echo "INFO: Backup of '$dir' successful: $file_name"
+done
+
+# Suppression des backups plus vieux que ${RETENTION_DAYS} jours
+find "$BACKUP_DIR" -type f -name "*.tar.gz" -mtime +${RETENTION_DAYS} -delete
+echo "INFO: Cleaning of old backups done."