AWSGlueredshift_tmp_dir目录逐渐增大
创始人
2024-09-25 16:01:48
0
  1. 在AWS Glue作业脚本中添加以下代码段,以在目录变得太大时清除redshift_tmp_dir目录中的文件。
import boto3
import os
import shutil

client = boto3.client('glue')
job_name = os.environ['AWS_SimpleWorkflow_JOB_NAME']
response = client.get_job_run(JobName=job_name, RunId=job_run_id)

# Set the maximum allowed size of the redshift_tmp_dir directory (in bytes)
max_size_bytes = 104857600

# Get the size of the redshift_tmp_dir directory (in bytes)
dir_size_bytes = sum(os.path.getsize(os.path.join(sftp_root, f)) for f in os.listdir(redshift_tmp_dir) if os.path.isfile(os.path.join(redshift_tmp_dir, f)))

# If the directory size is greater than the maximum allowed size, delete the oldest files until the directory size is under the limit
if dir_size_bytes > max_size_bytes:
    file_list = os.listdir(redshift_tmp_dir)
    file_list.sort(key=lambda x: os.stat(os.path.join(redshift_tmp_dir, x)).st_mtime)
    for filename in file_list:
        file_path = os.path.join(redshift_tmp_dir, filename)
        if os.path.isfile(file_path):
            os.remove(file_path)
        dir_size_bytes = sum(os.path.getsize(os.path.join(sftp_root, f)) for f in os.listdir(redshift_tmp_dir) if os.path.isfile(os.path.join(redshift_tmp_dir, f)))
        if dir_size_bytes <= max_size_bytes:
            break

  1. 如果仅想在AWS Glue作业运行时手动清理redshift_tmp_dir目录,请执行以下操作:
  • 首先,在Amazon S3上创建一个桶,以便作为放置日志文件的目录。

  • 在AWS Glue控制台中为该作业创建一个新的日志器。

  • 再次更新AWS Glue作业脚本,以在目录达到一定大小时手动运行清理命令。 例如,在此示例中,如果redshift_tmp_dir目录中的文件

相关内容

热门资讯

第8分钟辅助!wepoker怎... 第8分钟辅助!wepoker怎么开辅助,黑侠破解wepoker,课程教程(今日头条)1、上手简单,内...
第十分钟辅助!如何下载wpk透... 第十分钟辅助!如何下载wpk透视版,pokerworld软件,策略教程(有挂分享)如何下载wpk透视...
九分钟辅助!wepoker辅助... 九分钟辅助!wepoker辅助真的假的,cloudpoker作弊,手筋教程(证实有挂)1、每一步都需...
第十分钟辅助!wejoker辅... 第十分钟辅助!wejoker辅助器怎么卖,wepoker免费透视脚本,窍门教程(有挂方式)1、进入游...
十分钟辅助!wepoker-h... 十分钟辅助!wepoker-h5下载,pokernow辅助控制,绝活教程(有挂实锤)1、点击下载安装...
5分钟辅助!aapoker辅助... 5分钟辅助!aapoker辅助器怎么用,wepoker模拟器哪个好用,模板教程(有挂辅助)wepok...
八分钟辅助!wpk官网下载链接... 八分钟辅助!wpk官网下载链接,wpk透视怎么安装,教程书教程(有挂分享)该软件可以轻松地帮助玩家将...
9分钟辅助!wepoker怎么... 9分钟辅助!wepoker怎么买辅助,wepoker安装教程,课程教程(有挂方略)1、wepoker...
第七分钟辅助!hh poker... 第七分钟辅助!hh poker插件下载,wepoker科技辅助器,教程书教程(有挂教程)wepoke...
三分钟辅助!hhpoker脚本... 三分钟辅助!hhpoker脚本下载,hhpoker辅助器,举措教程(有挂教程)三分钟辅助!hhpok...