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"