缩小尺寸的多个 Azure blob 版本

问题描述 投票:0回答:1

我正在从应用程序将日志文件上传到 Azure。我看到同一内容的多个版本 “.log”文件的大小在一小时内减小。

最初 1.1Mb 的文件经过 11 个版本减少到 54 字节!

我团队中的每个人都声称没有读取或写入这些日志文件,并且这些文件上传一次并从另一台设备上的存储中删除。

有什么方法可以让我找出是什么在创建日志文件的版本吗?

我从未见过这种行为。我们经常使用 Azure blob 存储。

我已经寻找过这些 blob 文件的其他作者或读者。

azure azure-functions azure-blob-storage
1个回答
0
投票

有什么方法可以让我找出是什么在创建日志文件的版本吗?

这里在 Azure Blob 存储中创建了同一日志文件的多个版本,其大小随着时间的推移而减小,我修改了提供的 Python 脚本。

代码:

from azure.storage.blob import BlobServiceClient, BlobClient, ContentSettings
import time
import random
import string

# Define your Azure Storage account details
account_name = 'your_storage_account_name'
account_key = 'your_storage_account_key'
container_name = 'your_container_name'

# Create a BlobServiceClient using the storage account credentials
connection_string = f"DefaultEndpointsProtocol=https;AccountName={account_name};AccountKey={account_key};EndpointSuffix=core.windows.net"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

# Create the blob container if it doesn't exist
container_client = blob_service_client.get_container_client(container_name)
container_client.create_container()

# Define a function to generate random log data
def generate_log_data(size):
    return ''.join(random.choices(string.ascii_letters + string.digits, k=size))

# Define the filename and path for the log file
log_file_name = 'sample_log_file.log'

# Define the initial size of the log file
initial_size = 1100000  # 1.1 MB in bytes

# Define the number of iterations to simulate
num_iterations = 11

# Upload the log file to Azure Blob Storage and modify it multiple times
for i in range(num_iterations):
    # Generate random log data with reduced size over time
    log_data = generate_log_data(initial_size // (2 ** i))

    # Upload the log file to Azure Blob Storage
    blob_client = blob_service_client.get_blob_client(container=container_name, blob=log_file_name)
    blob_client.upload_blob(log_data, overwrite=True, content_settings=ContentSettings(content_type='text/plain'))

    print(f"Iteration {i + 1}: Uploaded log file with size {len(log_data)} bytes")

    # Simulate a delay before the next iteration
    time.sleep(3600)  # 1 hour delay

  • 通过将初始大小 (1.1 MB) 除以 2,日志文件的大小在每次迭代中减少一半。

  • 该脚本每小时(3600 秒)将日志文件上传到 Azure Blob 存储,进行 11 次迭代,模拟大小随着时间的推移而减小。

日志文件:

enter image description here

斑点大小:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.