From f028ac2d4eb51f4b1d53feb7f4ece7f81997a801 Mon Sep 17 00:00:00 2001 From: Moritz Utcke Date: Fri, 1 Aug 2025 08:37:49 -0500 Subject: [PATCH] =?UTF-8?q?F=C3=BCgt=20eine=20Auswahlm=C3=B6glichkeit=20f?= =?UTF-8?q?=C3=BCr=20eine=20Datenbank=20hinzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- recover-db-dev.bash | 52 +++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/recover-db-dev.bash b/recover-db-dev.bash index a26cf714..110a1352 100644 --- a/recover-db-dev.bash +++ b/recover-db-dev.bash @@ -5,27 +5,43 @@ BUCKET_NAME="ibc-db-backup" ENDPOINT_URL="https://s3.eu-central-3.ionoscloud.com" LOCAL_DOWNLOAD_DIR="./" # Where to save the file -# === Get latest file from IONOS S3 bucket === -LATEST_FILE=$(aws s3api list-objects-v2 \ - --bucket "$BUCKET_NAME" \ - --prefix "data-dump" \ - --endpoint-url "$ENDPOINT_URL" \ - --query 'Contents | sort_by(@, &LastModified) | [-1].Key' \ - --output text) +# === Check if a custom file is given as a command line argument === +if [ $# -eq 1 ]; then + CUSTOM_FILE="$1" + echo "🔍 Using custom file: $CUSTOM_FILE" + # Check if the file exists + if [ ! -f "$CUSTOM_FILE" ]; then + echo "❌ Custom file does not exist: $CUSTOM_FILE" + exit 1 + fi + LATEST_FILE="$CUSTOM_FILE" + FILENAME=$(basename "$LATEST_FILE") + SQL_FILE="${FILENAME%.br}" # Remove .br suffix +else + echo "🔍 No custom file provided, searching for latest .sql.br file in S3" -# === Check if file was found === -if [ "$LATEST_FILE" == "None" ] || [ -z "$LATEST_FILE" ]; then - echo "❌ No matching .sql.br file found." - exit 1 + # === Get latest file from IONOS S3 bucket === + LATEST_FILE=$(aws s3api list-objects-v2 \ + --bucket "$BUCKET_NAME" \ + --prefix "data-dump" \ + --endpoint-url "$ENDPOINT_URL" \ + --query 'Contents | sort_by(@, &LastModified) | [-1].Key' \ + --output text) + + # === Check if file was found === + if [ "$LATEST_FILE" == "None" ] || [ -z "$LATEST_FILE" ]; then + echo "❌ No matching .sql.br file found." + exit 1 + fi + echo "🔍 Latest file found: $LATEST_FILE" + FILENAME=$(basename "$LATEST_FILE") + SQL_FILE="${FILENAME%.br}" # Remove .br suffix + + echo "📥 Downloading $LATEST_FILE" + aws s3 cp "s3://$BUCKET_NAME/$LATEST_FILE" "$LOCAL_DOWNLOAD_DIR" \ + --endpoint-url "$ENDPOINT_URL" fi -FILENAME=$(basename "$LATEST_FILE") -SQL_FILE="${FILENAME%.br}" # Remove .br suffix - -echo "📥 Downloading $LATEST_FILE" -aws s3 cp "s3://$BUCKET_NAME/$LATEST_FILE" "$LOCAL_DOWNLOAD_DIR" \ - --endpoint-url "$ENDPOINT_URL" - # === Decompress with Brotli === echo "🗜️ Decompressing $FILENAME -> $SQL_FILE" brotli -d "$FILENAME"