s3_sync.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:odl-video-service 作者: mitodl 项目源码 文件源码
def sync_local_to_s3(local_video_records_done_folder,
                     s3_bucket_name,
                     s3_sync_result_file):
    """
    Sync local files to specified S3 bucket

    Args:
      local_video_records_done_folder (str): local folder containing video
        files ready to be copied to S3.
      s3_bucket_name (str): s3 bucket name
    """
    s3_sync_cmd = 'aws s3 sync {} s3://{} > "{}"'.format(local_video_records_done_folder,
                                                         s3_bucket_name,
                                                         s3_sync_result_file)
    try:
        cmd_output = subprocess.run(s3_sync_cmd,
                                    check=True,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
    except subprocess.SubprocessError as err:
        logger.exception("Failed to sync local files to s3 bucket")
        notify_slack_channel(f"Sync failed: *{computer_name}* \n `{err}`")
        sys.exit("[-] Failed to sync local files to s3 bucket")
    logger.info("S3 sync successfully ran: {}", cmd_output)
    notify_slack_channel(f"Sync succeeded on: *{computer_name}* \n `str({cmd_output})`")
    logger.info("Syncing complete")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号