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目录中的文件

相关内容

热门资讯

一分钟揭秘!微扑克有辅助软件吗... 一分钟揭秘!微扑克有辅助软件吗,aapoker挂,我来教教你(固有有挂)1、aapoker挂ai辅助...
重大发现!wpk德州辅助,we... 重大发现!wpk德州辅助,wepoke有挂,微扑克教程(原本有挂)1.wepoke有挂 ai辅助创建...
总算明白!微扑克辅助器是真的么... 总算明白!微扑克辅助器是真的么,德州ai辅助有用,力荐教程(都是是真的有挂)1、构建自己的微扑克辅助...
玩家必备科技!gg扑克辅助,w... 玩家必备科技!gg扑克辅助,wepoke辅助有挂,AI教程(确实真的是有挂)1、在wepoke辅助有...
重大来袭!cloudpoker... 重大来袭!cloudpoker辅助器,wepoke真的有挂,力荐教程(固有真的有挂)1、wepoke...
最新技巧!wepoke透明真的... 最新技巧!wepoke透明真的吗,智星德州菠萝有挂吗,AI教程(最初有挂);人气非常高,ai更新快且...
一分钟快速了解!德州微扑克辅助... 一分钟快速了解!德州微扑克辅助,德州微扑克辅助,高科技教程(好像存在有挂)是一款可以让一直输的玩家,...
一分钟教会你!wpk有吗,德州... 一分钟教会你!wpk有吗,德州ai辅助软件,玩家教你(固有是真的有挂)德州ai辅助软件辅助器中分为三...
实操分享!微扑克辅助,德州ai... 实操分享!微扑克辅助,德州ai机器人,科技教程(真是有挂)1、超多福利:超高返利,海量正版游戏,德州...
玩家必看科普!微扑克有辅助软件... 自定义aapoker辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不...