Loki scripts
Jump to navigation
Jump to search
import os from azure.storage.blob import ContainerClient # Set environment variables or hardcode for testing ACCOUNT_URL = os.environ["AZURE_ACCOUNT_URL"] # e.g., "https://myaccount.blob.core.windows.net" CONTAINER = os.environ["AZURE_CONTAINER_NAME"] # e.g., "loki-chunks" ACCOUNT_KEY = os.environ["AZURE_ACCOUNT_KEY"] SIZE_THRESHOLD = 100 * 1024 # e.g., 100KB # Connect to container container_client = ContainerClient( account_url=ACCOUNT_URL, container_name=CONTAINER, credential=ACCOUNT_KEY ) print(f"Scanning container '{CONTAINER}' for small chunks...") to_delete = [] for blob in container_client.list_blobs(name_starts_with=""): if blob.size < SIZE_THRESHOLD: print(f"- {blob.name} ({blob.size} bytes)") to_delete.append(blob.name) # Confirm and delete if to_delete: confirm = input(f"Delete {len(to_delete)} small blobs? (y/n): ") if confirm.lower() == 'y': for name in to_delete: container_client.delete_blob(name) print("Deleted.") else: print("No small blobs found.")