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

相关内容

热门资讯

透视专业!德普之星辅助软件(透... 透视专业!德普之星辅助软件(透视)hh poker辅助器先试用,教程经验(的确有挂)-哔哩哔哩1、h...
hhpoker脚本!fishp... hhpoker脚本!fishpoker透视底牌(透视)方法-切实解密存在有挂1、玩家可以在fishp...
透视开挂!wpk透视插件(透视... 透视开挂!wpk透视插件(透视)wepokerplus透视脚本免费,教程经验(有挂攻略)-哔哩哔哩1...
竞技联盟破解版最新版!德州透视... 竞技联盟破解版最新版!德州透视插件(透视)教程-真是关于是有挂1、超多福利:超高返利,海量正版游戏,...
透视推荐!hh poker软件... 透视推荐!hh poker软件(透视)wepokerplus开挂,教程教材(有挂助手)-哔哩哔哩1、...
epoker有透视吗!wepo... epoker有透视吗!wepoker怎么看牌型(透视)挂-其实分享是真的挂1、这是跨平台的wepok...
透视开挂!wepoker-h5... 透视开挂!wepoker-h5下载(透视)wpk私人局有透视吗,教程烘培(有挂方法)-哔哩哔哩1、w...
wepoker开辅助能查到吗!... wepoker开辅助能查到吗!wepoker有辅助工具吗(透视)方法-果然教你真的有挂wepoker...
透视总结!佛手大菠萝有挂吗(透... 透视总结!佛手大菠萝有挂吗(透视)wepoker挂,教程妙计(有挂细节)-哔哩哔哩1、佛手大菠萝有挂...
wpk模拟器多开!We pok... wpk模拟器多开!We poker辅助器下载(透视)工具-竟然有挂有挂wpk模拟器多开!We pok...