check every S3 bucket for Arq data, not just ones with pre-defined names

This commit is contained in:
Stefan Reitshamer 2011-10-23 06:00:12 -04:00
parent 68ef02f1ac
commit 23ba1cc792
4 changed files with 233 additions and 44 deletions

View file

@ -43,6 +43,7 @@
#import "UserAndComputer.h" #import "UserAndComputer.h"
#import "ArqSalt.h" #import "ArqSalt.h"
#import "ArqRepo.h" #import "ArqRepo.h"
#import "BackupSet.h"
@interface ArqRestoreCommand (internal) @interface ArqRestoreCommand (internal)
- (BOOL)printArqFolders:(NSError **)error; - (BOOL)printArqFolders:(NSError **)error;
@ -119,35 +120,23 @@
if (![self validateS3Keys:error]) { if (![self validateS3Keys:error]) {
return NO; return NO;
} }
for (NSString *s3BucketName in [S3Service s3BucketNamesForAccessKeyID:accessKey]) {
printf("S3 bucket: %s", [s3BucketName UTF8String]); NSArray *backupSets = [BackupSet allBackupSetsForAccessKeyID:accessKey secretAccessKey:secretKey error:error];
NSString *computerUUIDPrefix = [NSString stringWithFormat:@"/%@/", s3BucketName]; if (backupSets == nil) {
NSError *myError = nil;
NSArray *computerUUIDs = [s3 commonPrefixesForPathPrefix:computerUUIDPrefix delimiter:@"/" error:&myError];
if (computerUUIDs == nil && ![myError isErrorWithDomain:[S3Service errorDomain] code:ERROR_NOT_FOUND]) {
if (error != NULL) {
*error = myError;
}
return NO; return NO;
} }
if ([computerUUIDs count] == 0) { for (BackupSet *backupSet in backupSets) {
printf(" (no computers found)"); NSString *s3BucketName = [backupSet s3BucketName];
} NSString *computerUUID = [backupSet computerUUID];
printf("\n"); UserAndComputer *uac = [backupSet userAndComputer];
for (NSString *computerUUID in computerUUIDs) { printf("S3 bucket: %s", [s3BucketName UTF8String]);
NSString *computerInfoPath = [NSString stringWithFormat:@"/%@/%@/computerinfo", s3BucketName, computerUUID]; if (uac != nil) {
NSError *uacError = nil;
NSData *uacData = [s3 dataAtPath:computerInfoPath error:&uacError];
UserAndComputer *uac = nil;
if (uacData != nil) {
uac = [[[UserAndComputer alloc] initWithXMLData:uacData error:&uacError] autorelease];
printf(" %s (%s)", [[uac computerName] UTF8String], [[uac userName] UTF8String]); printf(" %s (%s)", [[uac computerName] UTF8String], [[uac userName] UTF8String]);
} else { } else {
printf(" (unknown computer)"); printf(" (unknown computer)");
} }
printf(" UUID %s", [computerUUID UTF8String]); printf(" UUID %s", [computerUUID UTF8String]);
NSString *computerUUIDPath = [computerUUIDPrefix stringByAppendingPathComponent:computerUUID]; NSString *computerBucketsPrefix = [NSString stringWithFormat:@"/%@/%@/buckets", s3BucketName, computerUUID];
NSString *computerBucketsPrefix = [computerUUIDPath stringByAppendingPathComponent:@"buckets"];
NSArray *s3BucketUUIDPaths = [s3 pathsWithPrefix:computerBucketsPrefix error:error]; NSArray *s3BucketUUIDPaths = [s3 pathsWithPrefix:computerBucketsPrefix error:error];
if (s3BucketUUIDPaths == nil) { if (s3BucketUUIDPaths == nil) {
return NO; return NO;
@ -170,7 +159,6 @@
printf(" restore command: arq_restore %s\n", [uuidPath UTF8String]); printf(" restore command: arq_restore %s\n", [uuidPath UTF8String]);
} }
} }
}
return YES; return YES;
} }
- (BOOL)restorePath:(NSError **)error { - (BOOL)restorePath:(NSError **)error {

53
BackupSet.h Normal file
View file

@ -0,0 +1,53 @@
/*
Copyright (c) 2010, 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 <Cocoa/Cocoa.h>
@class UserAndComputer;
@interface BackupSet : NSObject {
NSString *accessKeyID;
NSString *secretAccessKey;
NSString *s3BucketName;
NSString *computerUUID;
UserAndComputer *uac;
}
+ (NSArray *)allBackupSetsForAccessKeyID:(NSString *)theAccessKeyID secretAccessKey:(NSString *)theSecretAccessKey error:(NSError **)error;
- (id)initWithAccessKeyID:(NSString *)theAccessKeyID
secretAccessKey:(NSString *)theSecretAccessKey
s3BucketName:(NSString *)theS3BucketName
computerUUID:(NSString *)theComputerUUID
userAndComputer:(UserAndComputer *)theUAC;
- (NSString *)s3BucketName;
- (NSString *)computerUUID;
- (UserAndComputer *)userAndComputer;
@end

134
BackupSet.m Normal file
View file

@ -0,0 +1,134 @@
/*
Copyright (c) 2010, 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 "BackupSet.h"
#import "S3AuthorizationProvider.h"
#import "S3Service.h"
#import "UserAndComputer.h"
#import "NSErrorCodes.h"
#import "NSData-Encrypt.h"
#import "CryptoKey.h"
#import "RegexKitLite.h"
#import "ArqRepo.h"
#import "BlobKey.h"
#import "SetNSError.h"
#import "Commit.h"
#import "S3ObjectMetadata.h"
#import "ArqSalt.h"
@implementation BackupSet
+ (NSArray *)allBackupSetsForAccessKeyID:(NSString *)theAccessKeyID secretAccessKey:(NSString *)theSecretAccessKey error:(NSError **)error {
S3AuthorizationProvider *sap = [[[S3AuthorizationProvider alloc] initWithAccessKey:theAccessKeyID secretKey:theSecretAccessKey] autorelease];
S3Service *s3 = [[[S3Service alloc] initWithS3AuthorizationProvider:sap useSSL:YES retryOnTransientError:NO] autorelease];
NSArray *s3BucketNames = [s3 s3BucketNames:error];
if (s3BucketNames == nil) {
return nil;
}
NSMutableArray *ret = [NSMutableArray array];
for (NSString *theS3BucketName in s3BucketNames) {
if ([theS3BucketName rangeOfString:@"-com-haystacksoftware-arq"].location == NSNotFound
&& [theS3BucketName rangeOfString:@".com.haystacksoftware.arq"].location == NSNotFound) {
HSLogDebug(@"skipping bucket %@", theS3BucketName);
} else {
NSString *queryPrefix = [NSString stringWithFormat:@"/%@/", [theS3BucketName lowercaseString]];
NSArray *theS3ComputerUUIDs = [s3 commonPrefixesForPathPrefix:queryPrefix delimiter:@"/" error:error];
if (theS3ComputerUUIDs == nil) {
return nil;
}
for (NSString *s3ComputerUUID in theS3ComputerUUIDs) {
NSString *computerInfoPath = [NSString stringWithFormat:@"/%@/%@/computerinfo", theS3BucketName, s3ComputerUUID];
NSError *uacError = nil;
NSData *uacData = [s3 dataAtPath:computerInfoPath error:&uacError];
UserAndComputer *uac = nil;
if (uacData != nil) {
uac = [[[UserAndComputer alloc] initWithXMLData:uacData error:&uacError] autorelease];
if (uac == nil) {
HSLogError(@"error parsing UserAndComputer data: %@", uacError);
}
}
BackupSet *backupSet = [[[BackupSet alloc] initWithAccessKeyID:theAccessKeyID
secretAccessKey:theSecretAccessKey
s3BucketName:theS3BucketName
computerUUID:s3ComputerUUID
userAndComputer:uac] autorelease];
[ret addObject:backupSet];
}
}
}
NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"description" ascending:YES] autorelease];
[ret sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];
return ret;
}
- (id)initWithAccessKeyID:(NSString *)theAccessKeyID
secretAccessKey:(NSString *)theSecretAccessKey
s3BucketName:(NSString *)theS3BucketName
computerUUID:(NSString *)theComputerUUID
userAndComputer:(UserAndComputer *)theUAC {
if (self = [super init]) {
accessKeyID = [theAccessKeyID retain];
secretAccessKey = [theSecretAccessKey retain];
s3BucketName = [theS3BucketName retain];
computerUUID = [theComputerUUID retain];
uac = [theUAC retain];
}
return self;
}
- (void)dealloc {
[accessKeyID release];
[secretAccessKey release];
[s3BucketName release];
[computerUUID release];
[uac release];
[super dealloc];
}
- (NSString *)s3BucketName {
return s3BucketName;
}
- (NSString *)computerUUID {
return computerUUID;
}
- (UserAndComputer *)userAndComputer {
return uac;
}
#pragma mark NSObject
- (NSString *)description {
NSString *bucketRegion = [S3Service displayNameForBucketRegion:[S3Service s3BucketRegionForS3BucketName:s3BucketName]];
if (uac != nil) {
return [NSString stringWithFormat:@"%@ (%@) : %@ (%@)", [uac computerName], [uac userName], bucketRegion, computerUUID];
}
return [NSString stringWithFormat:@"unknown computer : %@ (%@)", bucketRegion, computerUUID];
}
@end

View file

@ -50,6 +50,7 @@
F805B8A11160EBAA007EC01E /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F805B8A01160EBAA007EC01E /* CoreFoundation.framework */; }; F805B8A11160EBAA007EC01E /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F805B8A01160EBAA007EC01E /* CoreFoundation.framework */; };
F805B8C21160EC41007EC01E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F805B8C11160EC41007EC01E /* Security.framework */; }; F805B8C21160EC41007EC01E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F805B8C11160EC41007EC01E /* Security.framework */; };
F805B8CE1160ECD7007EC01E /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F805B8CD1160ECD7007EC01E /* CoreServices.framework */; }; F805B8CE1160ECD7007EC01E /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F805B8CD1160ECD7007EC01E /* CoreServices.framework */; };
F81426D714541A6C00D7E50A /* BackupSet.m in Sources */ = {isa = PBXBuildFile; fileRef = F81426D614541A6C00D7E50A /* BackupSet.m */; };
F83C1A7411CA7C170001958F /* ArqRestoreCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F805B54C1160D3E6007EC01E /* ArqRestoreCommand.m */; }; F83C1A7411CA7C170001958F /* ArqRestoreCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F805B54C1160D3E6007EC01E /* ArqRestoreCommand.m */; };
F83C1A7711CA7C170001958F /* ArrayNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F805B7421160DCFE007EC01E /* ArrayNode.m */; }; F83C1A7711CA7C170001958F /* ArrayNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F805B7421160DCFE007EC01E /* ArrayNode.m */; };
F83C1A7811CA7C170001958F /* BooleanNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F805B7441160DCFE007EC01E /* BooleanNode.m */; }; F83C1A7811CA7C170001958F /* BooleanNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F805B7441160DCFE007EC01E /* BooleanNode.m */; };
@ -336,6 +337,8 @@
F805B8C11160EC41007EC01E /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; F805B8C11160EC41007EC01E /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
F805B8C51160EC4E007EC01E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; F805B8C51160EC4E007EC01E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
F805B8CD1160ECD7007EC01E /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; F805B8CD1160ECD7007EC01E /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
F81426D514541A6C00D7E50A /* BackupSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackupSet.h; sourceTree = "<group>"; };
F81426D614541A6C00D7E50A /* BackupSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BackupSet.m; sourceTree = "<group>"; };
F83C1A5F11CA7A6B0001958F /* arq_verify.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = arq_verify.m; sourceTree = "<group>"; }; F83C1A5F11CA7A6B0001958F /* arq_verify.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = arq_verify.m; sourceTree = "<group>"; };
F83C1A6111CA7BD20001958F /* ArqVerifyCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArqVerifyCommand.h; sourceTree = "<group>"; }; F83C1A6111CA7BD20001958F /* ArqVerifyCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArqVerifyCommand.h; sourceTree = "<group>"; };
F83C1A6211CA7BD20001958F /* ArqVerifyCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArqVerifyCommand.m; sourceTree = "<group>"; }; F83C1A6211CA7BD20001958F /* ArqVerifyCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArqVerifyCommand.m; sourceTree = "<group>"; };
@ -544,6 +547,8 @@
F8F4D67D121DA542002D09C1 /* UserAndComputer.m */, F8F4D67D121DA542002D09C1 /* UserAndComputer.m */,
F89A1F3C13FAC6820071D321 /* UserLibrary_Arq.h */, F89A1F3C13FAC6820071D321 /* UserLibrary_Arq.h */,
F89A1F3D13FAC6820071D321 /* UserLibrary_Arq.m */, F89A1F3D13FAC6820071D321 /* UserLibrary_Arq.m */,
F81426D514541A6C00D7E50A /* BackupSet.h */,
F81426D614541A6C00D7E50A /* BackupSet.m */,
); );
name = Source; name = Source;
sourceTree = "<group>"; sourceTree = "<group>";
@ -974,6 +979,7 @@
F89A200B13FADAD70071D321 /* ArqSalt.m in Sources */, F89A200B13FADAD70071D321 /* ArqSalt.m in Sources */,
F89A205413FAE2DA0071D321 /* LocalS3Signer.m in Sources */, F89A205413FAE2DA0071D321 /* LocalS3Signer.m in Sources */,
F89A205A13FAE3010071D321 /* DataOutputStream.m in Sources */, F89A205A13FAE3010071D321 /* DataOutputStream.m in Sources */,
F81426D714541A6C00D7E50A /* BackupSet.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -1088,7 +1094,11 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = (
x86_64,
i386,
ppc,
);
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES; GCC_ENABLE_FIX_AND_CONTINUE = YES;
@ -1108,7 +1118,11 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = (
x86_64,
i386,
ppc,
);
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;