From 30a1aaf422dd482d9a17a2b45c6ff718c6244dd7 Mon Sep 17 00:00:00 2001
From: Stefano Di Frischia <stefano.difrischia@inaf.it>
Date: Wed, 13 Sep 2023 12:42:06 +0000
Subject: [PATCH] L2SS-966: dump configdb before updating

---
 .gitignore              | 2 ++
 sbin/update_ConfigDb.sh | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/.gitignore b/.gitignore
index 69b645a3c..95968218c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,5 @@ deploy/hosts
 
 docker-compose/alerta-web/alerta-secrets.json
 docker-compose/tmp
+
+**/CDB/dump*.json
diff --git a/sbin/update_ConfigDb.sh b/sbin/update_ConfigDb.sh
index a8fab09f7..4e3fc4b21 100755
--- a/sbin/update_ConfigDb.sh
+++ b/sbin/update_ConfigDb.sh
@@ -9,6 +9,14 @@ else
     exit 1
 fi
 
+# dump a copy of the database before updating
+# Do not change -i into -it this will break integration tests in gitlab ci!
+docker exec -i dsconfig bash -c '
+  python -m dsconfig.dump > /tmp/dsconfig-configdb-dump.json
+  /manage_object_properties.py -r > /tmp/dsconfig-objectdb-dump.json
+  /merge_json.py /tmp/dsconfig-objectdb-dump.json /tmp/dsconfig-configdb-dump.json' \
+  > "${LOFAR20_DIR}"/CDB/dump_"$(date "+%Y.%m.%d_%H.%M.%S")".json
+
 # copy file into container to read it from container, as the file's location
 # in the container won't be the same as on the host.
 docker cp "${file}" dsconfig:/tmp/dsconfig-update-settings.json || exit 1
-- 
GitLab