From cf7439c8caf8703e0689114209f720476e3ccb72 Mon Sep 17 00:00:00 2001 From: AIIrondev Date: Wed, 29 Apr 2026 21:49:04 +0200 Subject: [PATCH] feat: Add backup functionality for instance with MongoDB using Docker Co-authored-by: Copilot --- Website/server_steering.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Website/server_steering.py b/Website/server_steering.py index 4bddca2..dfd64d8 100644 --- a/Website/server_steering.py +++ b/Website/server_steering.py @@ -180,6 +180,38 @@ class instace: counter += 1 return result + def backup(name: str) -> bool: + """ + Creates a backup of an instance with the subdomain [name].invario.eu + + Input: + - name -> String + + Output: + - bool if the backup works (True: backup worked; False: didnt work) + """ + import subprocess + try: + subprocess.run( + [ + "docker", + "compose", + "-f", + "docker-compose-multitenant.yml", + "exec", + "-T", + "mongodb", + "mongodump", + f"--archive=/data/backups/inventar_{name}-$(date +%Y%m%d%H%M%S).gz", + "--gzip", + "--db", + f"inventar_{name}" + ], + check=True + ) + return True + except subprocess.CalledProcessError: + return False class ussage: """