From f946cdd828081b845d1bd7fbc6b2e9b74fb4e963 Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Mon, 31 Mar 2025 16:20:53 +0200
Subject: [PATCH 01/10] Backup.sh

---
 backup.sh | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 backup.sh

diff --git a/backup.sh b/backup.sh
new file mode 100644
index 0000000..7af43bd
--- /dev/null
+++ b/backup.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+echo "Backing up Keycloak DB and config"
+
+out="backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
+tar -czf $out keycloak_db
+
+ls -lh $out
+echo "Done"
-- 
GitLab


From b3cad7fcee827237ccafc983a1004694da6be069 Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 1 Apr 2025 09:08:45 +0200
Subject: [PATCH 02/10] fix make directory

---
 backup.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/backup.sh b/backup.sh
index 7af43bd..23d213d 100644
--- a/backup.sh
+++ b/backup.sh
@@ -2,6 +2,11 @@
 
 echo "Backing up Keycloak DB and config"
 
+if [ ! -d "backups" ]; then
+  echo "backups does exist. Create this."
+  mkdir "backups"
+fi
+
 out="backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
 tar -czf $out keycloak_db
 
-- 
GitLab


From 5445820a4b7d39adee2253ccf33d647b2cf117c2 Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 1 Apr 2025 09:09:24 +0200
Subject: [PATCH 03/10] add backups to git ingore

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 52ca7bd..fef49d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
 keycloak_db/
 themes/*
 !themes/custom-theme-template
+backups
-- 
GitLab


From 147e952f68db1e7e34f6f9832d0b901931729887 Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 1 Apr 2025 16:21:11 +0200
Subject: [PATCH 04/10] Dump database with docker-compose or docker compose

---
 backup.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/backup.sh b/backup.sh
index 23d213d..f5a5707 100644
--- a/backup.sh
+++ b/backup.sh
@@ -8,7 +8,19 @@ if [ ! -d "backups" ]; then
 fi
 
 out="backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
-tar -czf $out keycloak_db
+. .env
+
+if command -v docker-compose &> /dev/null; then
+    echo "Usage of 'docker-compose'"
+    docker-compose exec -T db mysqldump --all-databases -u root -p$MARIADB_PASS  --default-character-set=utf8 | gzip > $out
+elif docker compose version &> /dev/null; then
+    echo "Usage of 'docker compose'"
+    docker compose exec -T db mysqldump --all-databases -u root -p$MARIADB_PASS  --default-character-set=utf8 | gzip > $out
+else
+    echo "'docker compose' and 'docker-compose' not found"
+    exit 1
+fi
+
 
 ls -lh $out
 echo "Done"
-- 
GitLab


From ace8a1e8916c6dfc355fdfee9ec9b8806a0d35c5 Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Wed, 2 Apr 2025 16:05:18 +0200
Subject: [PATCH 05/10] Remove echo and add variable docker_compose

---
 backup.sh | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/backup.sh b/backup.sh
index f5a5707..92d0393 100644
--- a/backup.sh
+++ b/backup.sh
@@ -3,7 +3,6 @@
 echo "Backing up Keycloak DB and config"
 
 if [ ! -d "backups" ]; then
-  echo "backups does exist. Create this."
   mkdir "backups"
 fi
 
@@ -11,16 +10,15 @@ out="backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
 . .env
 
 if command -v docker-compose &> /dev/null; then
-    echo "Usage of 'docker-compose'"
-    docker-compose exec -T db mysqldump --all-databases -u root -p$MARIADB_PASS  --default-character-set=utf8 | gzip > $out
+    DOCKER_COMPOSE="docker-compose"
 elif docker compose version &> /dev/null; then
-    echo "Usage of 'docker compose'"
-    docker compose exec -T db mysqldump --all-databases -u root -p$MARIADB_PASS  --default-character-set=utf8 | gzip > $out
+    DOCKER_COMPOSE="docker compose"
 else
     echo "'docker compose' and 'docker-compose' not found"
     exit 1
 fi
 
+$DOCKER_COMPOSE exec -T db mysqldump --all-databases -u root -p"$MARIADB_PASS" --default-character-set=utf8 | gzip > "$out"
 
 ls -lh $out
 echo "Done"
-- 
GitLab


From d6ea575f4d44d38e6cf550641d28b3940b318bf3 Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Wed, 2 Apr 2025 16:11:05 +0200
Subject: [PATCH 06/10] Protect MariaDB Pass variable

---
 backup.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/backup.sh b/backup.sh
index 92d0393..506bb96 100644
--- a/backup.sh
+++ b/backup.sh
@@ -2,6 +2,11 @@
 
 echo "Backing up Keycloak DB and config"
 
+if [ -z "$MARIADB_PASS" ]; then
+  echo "Error: the MARIADB_PASS variable is not set or is empty."
+  exit 1
+fi
+
 if [ ! -d "backups" ]; then
   mkdir "backups"
 fi
-- 
GitLab


From 0a95afc4c76db849c84d8acffd908965a08839c6 Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 8 Apr 2025 16:07:13 +0200
Subject: [PATCH 07/10] git ignore backups/*

---
 .gitignore | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index fef49d0..f412b94 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,4 @@
 keycloak_db/
 themes/*
 !themes/custom-theme-template
-backups
+backups/*
-- 
GitLab


From 83fcfe0909e3d911cc8e40d5b0f5426888ce4b4e Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 8 Apr 2025 16:12:22 +0200
Subject: [PATCH 08/10] Source .env with check, use -p for mkdir and check
 actual directory

---
 backup.sh | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/backup.sh b/backup.sh
index 506bb96..1a061e7 100644
--- a/backup.sh
+++ b/backup.sh
@@ -1,18 +1,25 @@
 #!/bin/bash
-
 echo "Backing up Keycloak DB and config"
 
+
+DIR=$(realpath $(dirname $0))
+
+if [ ! -e $DIR/.env ]
+then
+    echo ".env file do not exist"
+    exit 1
+fi
+
+. $DIR/.env
+
 if [ -z "$MARIADB_PASS" ]; then
   echo "Error: the MARIADB_PASS variable is not set or is empty."
   exit 1
 fi
 
-if [ ! -d "backups" ]; then
-  mkdir "backups"
-fi
+mkdir -p $DIR/backups`
 
-out="backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
-. .env
+out="$DIR/backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
 
 if command -v docker-compose &> /dev/null; then
     DOCKER_COMPOSE="docker-compose"
-- 
GitLab


From 8e04e4ac35af988bb112693fc0976bcd67a5afeb Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 8 Apr 2025 16:13:27 +0200
Subject: [PATCH 09/10] remove backquote

---
 backup.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backup.sh b/backup.sh
index 1a061e7..c0bf4e3 100644
--- a/backup.sh
+++ b/backup.sh
@@ -17,7 +17,7 @@ if [ -z "$MARIADB_PASS" ]; then
   exit 1
 fi
 
-mkdir -p $DIR/backups`
+mkdir -p $DIR/backups
 
 out="$DIR/backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
 
-- 
GitLab


From 6d8602adece0b965aae02b5c61b8a32203677e2f Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 8 Apr 2025 16:19:00 +0200
Subject: [PATCH 10/10] change name

---
 backup.sh          | 2 +-
 docker-compose.yml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/backup.sh b/backup.sh
index c0bf4e3..cddb142 100644
--- a/backup.sh
+++ b/backup.sh
@@ -30,7 +30,7 @@ else
     exit 1
 fi
 
-$DOCKER_COMPOSE exec -T db mysqldump --all-databases -u root -p"$MARIADB_PASS" --default-character-set=utf8 | gzip > "$out"
+$DOCKER_COMPOSE exec -T mariadb mysqldump --all-databases -u root -p"$MARIADB_PASS" --default-character-set=utf8 | gzip > "$out"
 
 ls -lh $out
 echo "Done"
diff --git a/docker-compose.yml b/docker-compose.yml
index 13fa03d..b6793e4 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -21,7 +21,7 @@ services:
 
     mariadb:
         image: mariadb:latest
-        container_name: mariadb
+        container_name: keycloak_mariadb
         volumes:
             - "./keycloak_db:/var/lib/mysql:rw"
         environment:
-- 
GitLab