2017-10-10 69 views
0

是否有命令行方式来恢复Glacier的数据? 到目前为止,我曾尝试:从Amazon Glacier恢复数据

s3cmd restore --recursive s3://mybucketname/folder/ 

aws s3 ls s3://<bucket_name> | awk '{print $4}' | xargs -L 1 aws s3api restore-object --restore-request Days=<days> --bucket <bucket_name> --key 

但是,没有帮助那里。 PS:我知道我们可以通过控制台做到这一点。

+0

当你说 “这里没有帮助”,你是什么意思?命令失败了吗?它成功了,但是你找不到S3对象?您应该从文档中了解到标准冰川检索时间通常为3-5小时,除非您要求加快(在这种情况下您需要支付更多费用)。 – jarmod

回答

0

不幸的是,这是不可能的。您只能使用Amazon S3访问已归档到Amazon Glacier的对象。

参见:http://docs.aws.amazon.com/AmazonS3/latest/user-guide/restore-archived-objects.html

+0

是的,我知道这种特殊的方式。 但是,即使通过控制台的限制,你不能恢复文件夹。恢复是在对象层面上,而不是在桶级别上。 我认为这不是一个好办法。 –

+0

S3没有文件夹。一个文件夹是一个逻辑概念,并不是S3中实际存在的东西。 S3中的所有对象都只是平面名称空间中的键。文件夹出现的事实只是一个逻辑概念,使用文件名字符“/”作为客户端软件中的分隔符。 –

-1

您可以使用下面的Python代码冰川数据恢复到S3。

import boto3, botocore 
import subprocess, os, shutil, tempfile, argparse, sys, time, codecs 
from pprint import pprint 

sys.stdout = codecs.getwriter('utf8')(sys.stdout) 

parser = argparse.ArgumentParser() 
parser.add_argument('--max-rate-mb', action='store', type=int, default=10000, help='The maximum rate in MB/h to restore files at. Files larger than this will not be restored.') 
parser.add_argument('--restore-days', action='store', type=int, default=30, help='How many days restored objects will remain in S3.') 
parser.add_argument('--restore-path', action='store', help='The bucket/prefix to restore from') 
parser.add_argument('--pretend', action='store_true', help='Do not execute restores') 
parser.add_argument('--estimate', action='store_true', help='When pretending, do not check for already-restored files') 
args = parser.parse_args() 

if not args.restore_path: 
    print 'No restore path specified.' 
    sys.exit(1) 

BUCKET = None 
PREFIX = None 
if '/' in args.restore_path: 
    BUCKET, PREFIX = args.restore_path.split('/',1) 
else: 
    BUCKET = args.restore_path 
    PREFIX = '' 

RATE_LIMIT_BYTES = args.max_rate_mb * 1024 * 1024 

s3 = boto3.Session(aws_access_key_id='<ACCESS_KEY>', aws_secret_access_key='<SECRET_KEY>').resource('s3') 
bucket = s3.Bucket(BUCKET) 

totalsize = 0 
objects = [] 

objcount = 0 
for objpage in bucket.objects.filter(Prefix=PREFIX).page_size(100).pages(): 
    for obj in objpage: 
     objcount += 1 
     print obj 
     objects.append(obj) 
    print u'Found {} objects.'.format(objcount) 
print 

objects.sort(key=lambda x: x.size, reverse=True) 

objects = filter(lambda x: x.storage_class == 'GLACIER', objects) 

if objects: 
    obj = objects[0] 
    print u'The largest object found is of {} size: {:14,d} {:1s} {}'.format(('a restorable' if obj.size <= RATE_LIMIT_BYTES else 'an UNRESTORABLE'), obj.size, obj.storage_class[0], obj.key) 
    print 

while objects: 
    current_set = [] 
    current_set_total = 0 
    unreported_unrestoreable_objects = [] 
    i = 0 
    while i < len(objects): 
     obj = objects[i] 

     if obj.size > RATE_LIMIT_BYTES: 
      unreported_unrestoreable_objects.append(obj) 
     elif unreported_unrestoreable_objects: 
      # No longer accumulating these. Print the ones we found. 
      print u'Some objects could not be restored due to exceeding the hourly rate limit:' 
      for obj in unreported_unrestoreable_objects: 
       print u'- {:14,d} {:1s} {}'.format(obj.size, obj.storage_class[0], obj.key) 
      print 

     if current_set_total + obj.size <= RATE_LIMIT_BYTES: 
      if not args.pretend or not args.estimate: 
       if obj.Object().restore is not None: 
        objects.pop(i) 
        continue 
      current_set.append(obj) 
      current_set_total += obj.size 
      objects.pop(i) 
      continue 
     i += 1 

    for obj in current_set: 
     print u'{:14,d} {:1s} {}'.format(obj.size, obj.storage_class[0], obj.key) 
     #pprint(obj.Object().restore) 
     if not args.pretend: 
      obj.restore_object(RestoreRequest={'Days': args.restore_days}) 
     #sys.exit(0) 

    print u'{:s} Requested restore of {:d} objects consisting of {:,d} bytes. {:d} objects remaining. {:,d} bytes of hourly restore rate wasted'.format(time.strftime('%Y-%m-%d %H:%M:%S'), len(current_set), current_set_total, len(objects), RATE_LIMIT_BYTES - current_set_total) 
    print 
    if not objects: 
     break 
    if not args.pretend: 
     time.sleep(3690) 

命令来运行脚本:

python restore_glacier_data_to_s3.py --restore-path s3-bucket-name/folder-name/ 
+0

尽管这个链接可能回答这个问题,但最好在这里包含答案的重要部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/17930206) – Maraboc