forked from arqbackup/arq_restore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArqRestoreCommand.m
587 lines (518 loc) · 27.1 KB
/
ArqRestoreCommand.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
/*
Copyright (c) 2009-2014, Stefan Reitshamer http://www.haystacksoftware.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the names of PhotoMinds LLC or Haystack Software, nor the names of
their contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "ArqRestoreCommand.h"
#import "Target.h"
#import "AWSRegion.h"
#import "BackupSet.h"
#import "S3Service.h"
#import "UserAndComputer.h"
#import "Bucket.h"
#import "Repo.h"
#import "S3RestorerParamSet.h"
#import "Tree.h"
#import "Commit.h"
#import "BlobKey.h"
#import "S3Restorer.h"
#import "S3GlacierRestorerParamSet.h"
#import "S3GlacierRestorer.h"
#import "GlacierRestorerParamSet.h"
#import "GlacierRestorer.h"
#import "S3AuthorizationProvider.h"
@implementation ArqRestoreCommand
- (void)dealloc {
[target release];
[super dealloc];
}
- (NSString *)errorDomain {
return @"ArqRestoreCommandErrorDomain";
}
- (BOOL)executeWithArgc:(int)argc argv:(const char **)argv error:(NSError **)error {
NSMutableArray *args = [NSMutableArray array];
for (int i = 0; i < argc; i++) {
[args addObject:[[[NSString alloc] initWithBytes:argv[i] length:strlen(argv[i]) encoding:NSUTF8StringEncoding] autorelease]];
}
if ([args count] < 2) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"missing arguments");
return NO;
}
int index = 1;
if ([[args objectAtIndex:1] isEqualToString:@"-l"]) {
if ([args count] < 4) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"missing arguments");
return NO;
}
setHSLogLevel(hsLogLevelForName([args objectAtIndex:2]));
index += 2;
}
NSString *cmd = [args objectAtIndex:index];
int targetParamsIndex = index + 1;
if ([cmd isEqualToString:@"listcomputers"]) {
// Valid command, but no additional args.
} else if ([cmd isEqualToString:@"listfolders"]) {
if ((argc - targetParamsIndex) < 2) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"missing arguments for listfolders command");
return NO;
}
targetParamsIndex += 2;
} else if ([cmd isEqualToString:@"restore"]) {
if ((argc - targetParamsIndex) < 4) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"missing arguments");
return NO;
}
targetParamsIndex += 4;
} else {
SETNSERROR([self errorDomain], ERROR_USAGE, @"unknown command: %@", cmd);
return NO;
}
if (targetParamsIndex >= argc) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"missing target type params");
return NO;
}
target = [[self targetForParams:[args subarrayWithRange:NSMakeRange(targetParamsIndex, argc - targetParamsIndex)] error:error] retain];
if (target == nil) {
return NO;
}
if ([cmd isEqualToString:@"listcomputers"]) {
if (![self listComputers:error]) {
return NO;
}
} else if ([cmd isEqualToString:@"listfolders"]) {
if (![self listBucketsForComputerUUID:[args objectAtIndex:index+1] encryptionPassword:[args objectAtIndex:index+2] error:error]) {
return NO;
}
} else if ([cmd isEqualToString:@"restore"]) {
if (![self restoreComputerUUID:[args objectAtIndex:index+1] bucketUUID:[args objectAtIndex:index+3] encryptionPassword:[args objectAtIndex:index+2] restoreBytesPerSecond:[args objectAtIndex:index+4] error:error]) {
return NO;
}
} else {
SETNSERROR([self errorDomain], ERROR_USAGE, @"unknown command: %@", cmd);
return NO;
}
return YES;
}
#pragma mark internal
- (Target *)targetForParams:(NSArray *)theParams error:(NSError **)error {
NSString *theTargetType = [theParams objectAtIndex:0];
Target *ret = nil;
if ([theTargetType isEqualToString:@"aws"]) {
if ([theParams count] != 4) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid aws parameters");
return nil;
}
NSString *theAccessKey = [theParams objectAtIndex:1];
NSString *theSecretKey = [theParams objectAtIndex:2];
NSString *theBucketName = [theParams objectAtIndex:3];
AWSRegion *awsRegion = [self awsRegionForAccessKey:theAccessKey secretKey:theSecretKey bucketName:theBucketName error:error];
if (awsRegion == nil) {
return nil;
}
NSURL *s3Endpoint = [awsRegion s3EndpointWithSSL:YES];
int port = [[s3Endpoint port] intValue];
NSString *portString = @"";
if (port != 0) {
portString = [NSString stringWithFormat:@":%d", port];
}
NSURL *targetEndpoint = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@@%@%@/%@", [s3Endpoint scheme], theAccessKey, [s3Endpoint host], portString, theBucketName]];
ret = [[[Target alloc] initWithEndpoint:targetEndpoint secret:theSecretKey passphrase:nil] autorelease];
} else if ([theTargetType isEqualToString:@"sftp"]) {
if ([theParams count] != 6 && [theParams count] != 7) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid sftp parameters");
return nil;
}
NSString *hostname = [theParams objectAtIndex:1];
int port = [[theParams objectAtIndex:2] intValue];
NSString *path = [theParams objectAtIndex:3];
NSString *username = [theParams objectAtIndex:4];
NSString *secret = [theParams objectAtIndex:5];
NSString *keyfilePassphrase = [theParams count] > 6 ? [theParams objectAtIndex:6] : nil;
if (![path hasPrefix:@"/"]) {
path = [@"/~/" stringByAppendingString:path];
}
NSString *escapedPath = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)path, NULL, (CFStringRef)@"!*'();:@&=+$,?%#[]", kCFStringEncodingUTF8);
NSString *escapedUsername = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)username, NULL, (CFStringRef)@"!*'();:@&=+$,?%#[]", kCFStringEncodingUTF8);
NSURL *endpoint = [NSURL URLWithString:[NSString stringWithFormat:@"sftp://%@@%@:%d%@", escapedUsername, hostname, port, escapedPath]];
ret = [[[Target alloc] initWithEndpoint:endpoint secret:secret passphrase:keyfilePassphrase] autorelease];
} else if ([theTargetType isEqualToString:@"greenqloud"]
|| [theTargetType isEqualToString:@"dreamobjects"]
|| [theTargetType isEqualToString:@"googlecloudstorage"]) {
if ([theParams count] != 4) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid %@ parameters", theTargetType);
return nil;
}
NSString *theAccessKey = [theParams objectAtIndex:1];
NSString *theSecretKey = [theParams objectAtIndex:2];
NSString *theBucketName = [theParams objectAtIndex:3];
NSString *theHostname = nil;
if ([theTargetType isEqualToString:@"greenqloud"]) {
theHostname = @"s.greenqloud.com";
} else if ([theTargetType isEqualToString:@"dreamobjects"]) {
theHostname = @"objects.dreamhost.com";
} else if ([theTargetType isEqualToString:@"googlecloudstorage"]) {
theHostname = @"storage.googleapis.com";
} else {
SETNSERROR([self errorDomain], ERROR_USAGE, @"no hostname for target type: %@", theTargetType);
return nil;
}
NSURL *endpoint = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@@%@/%@", theAccessKey, theHostname, theBucketName]];
ret = [[[Target alloc] initWithEndpoint:endpoint secret:theSecretKey passphrase:nil] autorelease];
} else if ([theTargetType isEqualToString:@"s3compatible"]) {
if ([theParams count] != 5) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid %@ parameters", theTargetType);
return nil;
}
NSURL *theURL = [NSURL URLWithString:[theParams objectAtIndex:1]];
if (theURL == nil) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid url %@", [theParams objectAtIndex:1]);
return nil;
}
NSString *theAccessKey = [theParams objectAtIndex:2];
NSString *theSecretKey = [theParams objectAtIndex:3];
NSString *theBucketName = [theParams objectAtIndex:4];
NSMutableString *urlString = [NSMutableString stringWithString:[theURL scheme]];
[urlString appendFormat:@"://%@@%@", theAccessKey, [theURL host]];
NSNumber *port = [theURL port];
if (port != nil) {
[urlString appendFormat:@":%d", [port intValue]];
}
[urlString appendString:@"/"];
[urlString appendString:theBucketName];
NSURL *endpoint = [NSURL URLWithString:urlString];
ret = [[[Target alloc] initWithEndpoint:endpoint secret:theSecretKey passphrase:nil] autorelease];
} else if ([theTargetType isEqualToString:@"googledrive"]) {
if ([theParams count] != 3) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid googledrive parameters");
return nil;
}
NSString *theRefreshToken = [theParams objectAtIndex:1];
NSString *thePath = [theParams objectAtIndex:2];
NSString *escapedPath = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)thePath, CFSTR("/"), CFSTR("@?=&+"), kCFStringEncodingUTF8);
[escapedPath autorelease];
NSURL *endpoint = [NSURL URLWithString:[NSString stringWithFormat:@"googledrive://unknown_email_address@www.googleapis.com%@", escapedPath]];
ret = [[[Target alloc] initWithEndpoint:endpoint secret:theRefreshToken passphrase:nil] autorelease];
} else {
SETNSERROR([self errorDomain], ERROR_USAGE, @"unknown target type: %@", theTargetType);
return nil;
}
return ret;
}
- (AWSRegion *)awsRegionForAccessKey:(NSString *)theAccessKey secretKey:(NSString *)theSecretKey bucketName:(NSString *)theBucketName error:(NSError **)error {
S3AuthorizationProvider *sap = [[[S3AuthorizationProvider alloc] initWithAccessKey:theAccessKey secretKey:theSecretKey] autorelease];
NSURL *endpoint = [[AWSRegion usEast1] s3EndpointWithSSL:YES];
S3Service *s3 = [[[S3Service alloc] initWithS3AuthorizationProvider:sap endpoint:endpoint useAmazonRRS:NO] autorelease];
NSString *location = [s3 locationOfS3Bucket:theBucketName targetConnectionDelegate:nil error:error];
if (location == nil) {
return nil;
}
return [AWSRegion regionWithLocation:location];
}
- (BOOL)listComputers:(NSError **)error {
NSArray *expandedTargetList = [self expandedTargetList:error];
if (expandedTargetList == nil) {
return NO;
}
NSMutableArray *ret = [NSMutableArray array];
for (Target *theTarget in expandedTargetList) {
NSError *myError = nil;
HSLogDebug(@"getting backup sets for %@", theTarget);
NSArray *backupSets = [BackupSet allBackupSetsForTarget:theTarget targetConnectionDelegate:nil error:&myError];
if (backupSets == nil) {
if ([myError isErrorWithDomain:[S3Service errorDomain] code:S3SERVICE_ERROR_AMAZON_ERROR] && [[[myError userInfo] objectForKey:@"HTTPStatusCode"] intValue] == 403) {
HSLogError(@"access denied getting backup sets for %@", theTarget);
} else {
HSLogError(@"error getting backup sets for %@: %@", theTarget, myError);
SETERRORFROMMYERROR;
return nil;
}
} else {
printf("target: %s\n", [[theTarget endpointDisplayName] UTF8String]);
for (BackupSet *backupSet in backupSets) {
printf("\tcomputer %s\n", [[backupSet computerUUID] UTF8String]);
printf("\t\t%s (%s)\n", [[[backupSet userAndComputer] computerName] UTF8String], [[[backupSet userAndComputer] userName] UTF8String]);
}
}
}
return ret;
}
- (NSArray *)expandedTargetList:(NSError **)error {
NSMutableArray *expandedTargetList = [NSMutableArray arrayWithObject:target];
// if ([target targetType] == kTargetAWS
// || [target targetType] == kTargetDreamObjects
// || [target targetType] == kTargetGoogleCloudStorage
// || [target targetType] == kTargetGreenQloud
// || [target targetType] == kTargetS3Compatible) {
// NSError *myError = nil;
// NSArray *targets = [self expandedTargetsForS3Target:target error:&myError];
// if (targets == nil) {
// HSLogError(@"failed to expand target list for %@: %@", target, myError);
// } else {
// [expandedTargetList setArray:targets];
// HSLogDebug(@"expandedTargetList is now: %@", expandedTargetList);
// }
// }
return expandedTargetList;
}
- (NSArray *)expandedTargetsForS3Target:(Target *)theTarget error:(NSError **)error {
S3Service *s3 = [theTarget s3:error];
if (s3 == nil) {
return nil;
}
NSArray *s3BucketNames = [s3 s3BucketNamesWithTargetConnectionDelegate:nil error:error];
if (s3BucketNames == nil) {
return nil;
}
HSLogDebug(@"s3BucketNames for %@: %@", theTarget, s3BucketNames);
NSURL *originalEndpoint = [theTarget endpoint];
NSMutableArray *ret = [NSMutableArray array];
for (NSString *s3BucketName in s3BucketNames) {
NSURL *endpoint = nil;
if ([theTarget targetType] == kTargetAWS) {
NSString *location = [s3 locationOfS3Bucket:s3BucketName targetConnectionDelegate:nil error:error];
if (location == nil) {
return nil;
}
AWSRegion *awsRegion = [AWSRegion regionWithLocation:location];
HSLogDebug(@"awsRegion for s3BucketName %@: %@", s3BucketName, location);
NSURL *s3Endpoint = [awsRegion s3EndpointWithSSL:YES];
HSLogDebug(@"s3Endpoint: %@", s3Endpoint);
endpoint = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@@%@/%@", [originalEndpoint user], [s3Endpoint host], s3BucketName]];
} else {
endpoint = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@@%@/%@", [originalEndpoint scheme], [originalEndpoint user], [originalEndpoint host], s3BucketName]];
}
HSLogDebug(@"endpoint: %@", endpoint);
Target *theTarget = [[[Target alloc] initWithEndpoint:endpoint secret:[theTarget secret:NULL] passphrase:[theTarget passphrase:NULL]] autorelease];
[ret addObject:theTarget];
}
return ret;
}
- (BOOL)listBucketsForComputerUUID:(NSString *)theComputerUUID encryptionPassword:(NSString *)theEncryptionPassword error:(NSError **)error {
NSArray *buckets = [Bucket bucketsWithTarget:target computerUUID:theComputerUUID encryptionPassword:theEncryptionPassword targetConnectionDelegate:nil error:error];
if (buckets == nil) {
return NO;
}
printf("target %s\n", [[target endpointDisplayName] UTF8String]);
printf("computer %s\n", [theComputerUUID UTF8String]);
for (Bucket *bucket in buckets) {
printf("\tfolder %s\n", [[bucket localPath] UTF8String]);
printf("\t\tuuid %s\n", [[bucket bucketUUID] UTF8String]);
}
return YES;
}
- (BOOL)restoreComputerUUID:(NSString *)theComputerUUID bucketUUID:(NSString *)theBucketUUID encryptionPassword:(NSString *)theEncryptionPassword restoreBytesPerSecond:(NSString *)theRestoreBytesPerSecond error:(NSError **)error {
Bucket *myBucket = nil;
NSArray *expandedTargetList = [self expandedTargetList:error];
if (expandedTargetList == nil) {
return NO;
}
for (Target *theTarget in expandedTargetList) {
NSArray *buckets = [Bucket bucketsWithTarget:theTarget computerUUID:theComputerUUID encryptionPassword:theEncryptionPassword targetConnectionDelegate:nil error:error];
if (buckets == nil) {
return NO;
}
for (Bucket *bucket in buckets) {
if ([[bucket bucketUUID] isEqualToString:theBucketUUID]) {
myBucket = bucket;
break;
}
}
if (myBucket != nil) {
break;
}
}
if (myBucket == nil) {
SETNSERROR([self errorDomain], ERROR_NOT_FOUND, @"folder %@ not found", theBucketUUID);
return NO;
}
Repo *repo = [[[Repo alloc] initWithBucket:myBucket encryptionPassword:theEncryptionPassword targetUID:getuid() targetGID:getgid() loadExistingMutablePackFiles:NO targetConnectionDelegate:nil repoDelegate:nil error:error] autorelease];
if (repo == nil) {
return NO;
}
BlobKey *commitBlobKey = [repo headBlobKey:error];
if (commitBlobKey == nil) {
return NO;
}
Commit *commit = [repo commitForBlobKey:commitBlobKey dataSize:NULL error:error];
if (commit == nil) {
return NO;
}
NSString *destinationPath = [[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent:[[myBucket localPath] lastPathComponent]];
if ([[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
SETNSERROR([self errorDomain], -1, @"%@ already exists", destinationPath);
return NO;
}
printf("target %s\n", [[[myBucket target] endpointDisplayName] UTF8String]);
printf("computer %s\n", [[myBucket computerUUID] UTF8String]);
printf("\nrestoring folder %s to %s\n\n", [[myBucket localPath] UTF8String], [destinationPath UTF8String]);
AWSRegion *region = [AWSRegion regionWithS3Endpoint:[target endpoint]];
BOOL isGlacierDestination = [region supportsGlacier];
if ([myBucket storageType] == StorageTypeGlacier && isGlacierDestination) {
int bytesPerSecond = [theRestoreBytesPerSecond intValue];
if (bytesPerSecond == 0) {
SETNSERROR([self errorDomain], -1, @"invalid bytes_per_second %@", theRestoreBytesPerSecond);
return NO;
}
GlacierRestorerParamSet *paramSet = [[[GlacierRestorerParamSet alloc] initWithBucket:myBucket
encryptionPassword:theEncryptionPassword
downloadBytesPerSecond:bytesPerSecond
commitBlobKey:commitBlobKey
rootItemName:[[myBucket localPath] lastPathComponent]
treeVersion:CURRENT_TREE_VERSION
treeIsCompressed:[[commit treeBlobKey] compressed]
treeBlobKey:[commit treeBlobKey]
nodeName:nil targetUID:getuid()
targetGID:getgid()
useTargetUIDAndGID:YES
destinationPath:destinationPath
logLevel:global_hslog_level] autorelease];
[[[GlacierRestorer alloc] initWithGlacierRestorerParamSet:paramSet delegate:self] autorelease];
} else if ([myBucket storageType] == StorageTypeS3Glacier && isGlacierDestination) {
int bytesPerSecond = [theRestoreBytesPerSecond intValue];
if (bytesPerSecond == 0) {
SETNSERROR([self errorDomain], -1, @"invalid bytes_per_second %@", theRestoreBytesPerSecond);
return NO;
}
S3GlacierRestorerParamSet *paramSet = [[[S3GlacierRestorerParamSet alloc] initWithBucket:myBucket
encryptionPassword:theEncryptionPassword
downloadBytesPerSecond:bytesPerSecond
commitBlobKey:commitBlobKey
rootItemName:[[myBucket localPath] lastPathComponent]
treeVersion:CURRENT_TREE_VERSION
treeIsCompressed:[[commit treeBlobKey] compressed]
treeBlobKey:[commit treeBlobKey]
nodeName:nil
targetUID:getuid()
targetGID:getgid()
useTargetUIDAndGID:YES
destinationPath:destinationPath
logLevel:global_hslog_level] autorelease];
S3GlacierRestorer *restorer = [[[S3GlacierRestorer alloc] initWithS3GlacierRestorerParamSet:paramSet delegate:self] autorelease];
[restorer run];
} else {
S3RestorerParamSet *paramSet = [[[S3RestorerParamSet alloc] initWithBucket:myBucket
encryptionPassword:theEncryptionPassword
commitBlobKey:commitBlobKey
rootItemName:[[myBucket localPath] lastPathComponent]
treeVersion:CURRENT_TREE_VERSION
treeIsCompressed:[[commit treeBlobKey] compressed]
treeBlobKey:[commit treeBlobKey]
nodeName:nil
targetUID:getuid()
targetGID:getgid()
useTargetUIDAndGID:YES
destinationPath:destinationPath
logLevel:global_hslog_level] autorelease];
[[[S3Restorer alloc] initWithParamSet:paramSet delegate:self] autorelease];
}
return YES;
}
#pragma mark S3RestorerDelegate
// Methods return YES if cancel is requested.
- (BOOL)s3RestorerMessageDidChange:(NSString *)message {
printf("status: %s\n", [message UTF8String]);
return NO;
}
- (BOOL)s3RestorerBytesTransferredDidChange:(NSNumber *)theTransferred {
return NO;
}
- (BOOL)s3RestorerTotalBytesToTransferDidChange:(NSNumber *)theTotal {
return NO;
}
- (BOOL)s3RestorerErrorMessage:(NSString *)theErrorMessage didOccurForPath:(NSString *)thePath {
printf("%s error: %s\n", [thePath UTF8String], [theErrorMessage UTF8String]);
return NO;
}
- (BOOL)s3RestorerDidSucceed {
return NO;
}
- (BOOL)s3RestorerDidFail:(NSError *)error {
printf("failed: %s\n", [[error localizedDescription] UTF8String]);
return NO;
}
#pragma mark S3GlacierRestorerDelegate
- (BOOL)s3GlacierRestorerMessageDidChange:(NSString *)message {
printf("status: %s\n", [message UTF8String]);
return NO;
}
- (BOOL)s3GlacierRestorerBytesRequestedDidChange:(NSNumber *)theRequested {
printf("requested %qu of %qu\n", [theRequested unsignedLongLongValue], maxRequested);
return NO;
}
- (BOOL)s3GlacierRestorerTotalBytesToRequestDidChange:(NSNumber *)theMaxRequested {
maxRequested = [theMaxRequested unsignedLongLongValue];
return NO;
}
- (BOOL)s3GlacierRestorerDidFinishRequesting {
return NO;
}
- (BOOL)s3GlacierRestorerBytesTransferredDidChange:(NSNumber *)theTransferred {
printf("restored %qu of %qu\n", [theTransferred unsignedLongLongValue], maxTransfer);
return NO;
}
- (BOOL)s3GlacierRestorerTotalBytesToTransferDidChange:(NSNumber *)theTotal {
maxTransfer = [theTotal unsignedLongLongValue];
return NO;
}
- (BOOL)s3GlacierRestorerErrorMessage:(NSString *)theErrorMessage didOccurForPath:(NSString *)thePath {
printf("%s error: %s\n", [thePath UTF8String], [theErrorMessage UTF8String]);
return NO;
}
- (void)s3GlacierRestorerDidSucceed {
printf("restore finished.\n");
}
- (void)s3GlacierRestorerDidFail:(NSError *)error {
printf("failed: %s\n", [[error localizedDescription] UTF8String]);
}
#pragma mark GlacierRestorerDelegate
- (BOOL)glacierRestorerMessageDidChange:(NSString *)message {
printf("status: %s\n", [message UTF8String]);
return NO;
}
- (BOOL)glacierRestorerBytesRequestedDidChange:(NSNumber *)theRequested {
return NO;
}
- (BOOL)glacierRestorerTotalBytesToRequestDidChange:(NSNumber *)theMaxRequested {
return NO;
}
- (BOOL)glacierRestorerDidFinishRequesting {
return NO;
}
- (BOOL)glacierRestorerBytesTransferredDidChange:(NSNumber *)theTransferred {
return NO;
}
- (BOOL)glacierRestorerTotalBytesToTransferDidChange:(NSNumber *)theTotal {
return NO;
}
- (BOOL)glacierRestorerErrorMessage:(NSString *)theErrorMessage didOccurForPath:(NSString *)thePath {
printf("%s error: %s\n", [thePath UTF8String], [theErrorMessage UTF8String]);
return NO;
}
- (BOOL)glacierRestorerDidSucceed {
return NO;
}
- (BOOL)glacierRestorerDidFail:(NSError *)error {
printf("failed: %s\n", [[error localizedDescription] UTF8String]);
return NO;
}
@end