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")
评论列表
文章目录