简体   繁体   English

使用Boto告诉文件何时成功上传到Glacier

[英]Using Boto to tell when a file has successfully been uploaded to Glacier

Currently I am using Amazon Web Services(AWS) and to open an S3 bucket, save its contents to a directory in an EC2, I then create a tar file from everything that is in that directory and push that tar file to AWS Glacier. 目前我正在使用Amazon Web Services(AWS)并打开S3存储桶,将其内容保存到EC2中的目录,然后从该目录中的所有内容创建tar文件并将该tar文件推送到AWS Glacier。 The last step that I was trying to accomplish was to have the script terminate when the tar file has been successfully upload to AWS Glacier (Which takes 3-5 hours). 我试图完成的最后一步是在tar文件成功上传到AWS Glacier时需要终止脚本(需要3-5个小时)。

Currently I am stumped as to how to take the archive_id and ask the vault if the tar file has been successfully loaded. 目前,我很难理解如何获取archive_id并询问保险库是否已成功加载tar文件。

To interact with AWS Glacier I have been using the python boto tool. 要与AWS Glacier交互,我一直在使用python boto工具。 I included the python\\boto code that uploads the file to glacier and some of the quick tests I have tried to run to just figure out if the code has successfully been uploaded or not. 我包含了将文件上传到冰川的python \\ boto代码以及我试图运行的一些快速测试,以确定代码是否已成功上传。 So far all of the tests return false. 到目前为止,所有测试都返回错误。

I excluded a few tests about the status_code which was also returning false for everything as well and when I try to print out any of these only the not completed and in progress (As expect) prints out anything, yet when I try to match the archive_id or retrieve_job to what is returned in the list of jobs I get no matches. 我排除了一些关于status_code的测试,这些测试也为所有内容返回false,当我尝试打印出任何这些时,只有未完成和正在进行中(正如预期)打印出任何内容,但是当我尝试匹配archive_id时或者retrieve_job到工作列表中返回的内容我没有匹配。 An additional note is the lists that these are saved in when it is printed they all the same ( Job(arn:aws:glacier:us-east-1:232412618534:vaults/glacier-poc) ) 另外一个注释是打印时保存的列表,它们都是相同的(Job(arn:aws:glacier:us-east-1:232412618534:vaults / glacier-poc))

How to return true when the job is completed? 如何在工作完成后返回true?

    import boto
    import sys

    ACCESS_KEY_ID = "..."
    SECRET_ACCESS_KEY = "..."
    FILENAME = sys.argv[1]
    GLACIER_VAULT_NAME = sys.argv[2]

    connection = boto.connect_glacier(aws_access_key_id=ACCESS_KEY_ID, aws_secret_access_key=SECRET_ACCESS_KEY)

    vault = connection.get_vault(GLACIER_VAULT_NAME)

    archive_id = vault.upload_archive(FILENAME)

    open("glacier.txt", "a").write(FILENAME + " " + archive_id + "\n")

    retrieve_job = vault.retrieve_archive(archive_id)

    a = vault.list_jobs(completed=True)
    b = vault.list_jobs(completed=False)

    print "Is In Completed List"
    print archive_id in a
    print "Is In NOT Completed List"
    print archive_id in b

    print "Is In Completed List"
    print retrieve_job in a
    print "Is In NOT Completed List"
    print retrieve_job in b

Take a look at this Boto and Glacier guide , you can either poll it manually from boto or you can set up Amazon Simple Notification Service to notify you when the job is done. 看看这个Boto和Glacier指南 ,您可以从boto手动轮询它,也可以设置Amazon Simple Notification Service以在作业完成时通知您。

archive_id = vault.upload_archive("mybackup.tgz")
retrieve_job = vault.retrieve_archive(archive_id)

# if the job is in progress
job_id = retrieve_job.id
retrieve_job = vault.get_job(job_id)

if retrieve_job.completed:
    job.download_to_file("mybackup.tgz")

You can use boto's set_vault_notifications function set the SNS notifications. 您可以使用boto的set_vault_notifications函数设置SNS通知。

notification_config = {'SNSTopic': 'my_notification_topic',
                       'Events': ['ArchiveRetrievalCompleted',
                                  'InventoryRetrievalCompleted']}
vault.set_vault_notifications(vault, notification_config)

Here is an extensive example of waiting for an upload by setting up SNS notification subscriptions to SQS queue service. 以下是通过设置SQS队列服务的SNS通知订阅来等待上载的广泛示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM