Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions src/main/java/com/instaclustr/esop/gcp/GCPBackuper.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ public FreshenResult freshenRemoteObject(ManifestEntry manifestEntry, final Remo

try {
if (!request.skipRefreshing) {
storage.copy(new Storage.CopyRequest.Builder()
.setSource(blobId)
.setTarget(BlobInfo.newBuilder(blobId).build(), Storage.BlobTargetOption.predefinedAcl(BUCKET_OWNER_FULL_CONTROL))
.build());
final BlobInfo.Builder targetBuilder = BlobInfo.newBuilder(blobId);
final Storage.CopyRequest.Builder copyBuilder = new Storage.CopyRequest.Builder()
.setSource(blobId)
.setTarget(targetBuilder.build());

// Only apply ACL if not using uniform bucket-level access
if (!request.gcpUniformBucketLevelAccess) {
copyBuilder.setTarget(targetBuilder.build(), Storage.BlobTargetOption.predefinedAcl(BUCKET_OWNER_FULL_CONTROL));
}

storage.copy(copyBuilder.build());

return FreshenResult.FRESHENED;
} else {
Expand All @@ -87,16 +94,37 @@ public void uploadFile(final ManifestEntry manifestEntry,
final RemoteObjectReference objectReference) throws Exception {
final BlobId blobId = ((GCPRemoteObjectReference) objectReference).blobId;

try (final WriteChannel outputChannel = storage.writer(BlobInfo.newBuilder(blobId).build(), Storage.BlobWriteOption.predefinedAcl(BUCKET_OWNER_FULL_CONTROL));
final ReadableByteChannel inputChannel = Channels.newChannel(localFileStream)) {
final BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();

// Only apply ACL if not using uniform bucket-level access
final WriteChannel outputChannel;
if (request.gcpUniformBucketLevelAccess) {
outputChannel = storage.writer(blobInfo);
} else {
outputChannel = storage.writer(blobInfo, Storage.BlobWriteOption.predefinedAcl(BUCKET_OWNER_FULL_CONTROL));
}

try (final ReadableByteChannel inputChannel = Channels.newChannel(localFileStream)) {
ByteStreams.copy(inputChannel, outputChannel);
} finally {
if (outputChannel != null) {
outputChannel.close();
}
}
}

@Override
public void uploadText(final String text, final RemoteObjectReference objectReference) {
final BlobId blobId = ((GCPRemoteObjectReference) objectReference).blobId;
storage.create(BlobInfo.newBuilder(blobId).build(), text.getBytes(), Storage.BlobTargetOption.predefinedAcl(BUCKET_OWNER_FULL_CONTROL));
final BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
final byte[] data = text.getBytes();

// Only apply ACL if not using uniform bucket-level access
if (request.gcpUniformBucketLevelAccess) {
storage.create(blobInfo, data);
} else {
storage.create(blobInfo, data, Storage.BlobTargetOption.predefinedAcl(BUCKET_OWNER_FULL_CONTROL));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public BackupCommitLogsOperationRequest(@JsonProperty("storageLocation") final S
@JsonProperty("proxySettings") final ProxySettings proxySettings,
@JsonProperty("retry") final RetrySpec retry,
@JsonProperty("skipRefreshing") final boolean skipRefreshing,
@JsonProperty("kmsKeyId") final String kmsKeyId) {
@JsonProperty("kmsKeyId") final String kmsKeyId,
@JsonProperty("gcpUniformBucketLevelAccess") final boolean gcpUniformBucketLevelAccess) {
super(storageLocation,
duration,
bandwidth,
Expand All @@ -87,7 +88,8 @@ public BackupCommitLogsOperationRequest(@JsonProperty("storageLocation") final S
retry,
skipRefreshing,
null,
kmsKeyId);
kmsKeyId,
gcpUniformBucketLevelAccess);
this.type = "commitlog-backup";
this.commitLogArchiveOverride = commitLogArchiveOverride;
this.commitLog = commitLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ private BackupOperation(@JsonProperty("type") final String type,
@JsonSerialize(using = ListPathSerializer.class)
@JsonDeserialize(contentUsing = PathDeserializer.class)
@JsonProperty("dataDirs") final List<Path> dataDirs,
@JsonProperty("kmsKeyId") final String kmsKeyId) {
@JsonProperty("kmsKeyId") final String kmsKeyId,
@JsonProperty("gcpUniformBucketLevelAccess") final boolean gcpUniformBucketLevelAccess) {
super(type, id, creationTime, state, errors, progress, startTime, new BackupOperationRequest(type,
storageLocation,
duration,
Expand All @@ -112,7 +113,8 @@ private BackupOperation(@JsonProperty("type") final String type,
retry,
skipRefreshing,
dataDirs,
kmsKeyId));
kmsKeyId,
gcpUniformBucketLevelAccess));
coordinator = null;
storageProviders = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public BackupOperationRequest(@JsonProperty("type") final String type,
@JsonSerialize(using = ListPathSerializer.class)
@JsonDeserialize(contentUsing = PathDeserializer.class)
@JsonProperty("dataDirs") final List<Path> dataDirs,
@JsonProperty("kmsKeyId") final String kmsKeyId) {
@JsonProperty("kmsKeyId") final String kmsKeyId,
@JsonProperty("gcpUniformBucketLevelAccess") final boolean gcpUniformBucketLevelAccess) {
super(storageLocation,
duration,
bandwidth,
Expand All @@ -114,7 +115,8 @@ public BackupOperationRequest(@JsonProperty("type") final String type,
retry,
skipRefreshing,
dataDirs,
kmsKeyId);
kmsKeyId,
gcpUniformBucketLevelAccess);
this.entities = entities == null ? DatabaseEntities.empty() : entities;
this.snapshotTag = snapshotTag == null ? format("autosnap-%d", MILLISECONDS.toSeconds(currentTimeMillis())) : snapshotTag;
this.globalRequest = globalRequest;
Expand Down Expand Up @@ -148,6 +150,7 @@ public String toString() {
.add("retry", retry)
.add("skipRefreshing", skipRefreshing)
.add("kmsKeyId", kmsKeyId)
.add("gcpUniformBucketLevelAccess", gcpUniformBucketLevelAccess)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public MetadataDirective convert(final String value) {
+ "based on which a respective local file will be upload or not, defaults to false, does not work with s3.")
public boolean skipRefreshing;

@JsonProperty("gcpUniformBucketLevelAccess")
@Option(names = "--gcp-uniform-bucket-level-access",
description = "For GCP storage, skip setting ACLs when bucket has uniform bucket-level access enabled. Defaults to false.")
public boolean gcpUniformBucketLevelAccess;

public BaseBackupOperationRequest() {
// for picocli
if (metadataDirective == null) {
Expand All @@ -83,13 +88,15 @@ public BaseBackupOperationRequest(final StorageLocation storageLocation,
final RetrySpec retrySpec,
final boolean skipRefreshing,
final List<Path> dataDirs,
final String kmsKeyId) {
final String kmsKeyId,
final boolean gcpUniformBucketLevelAccess) {
super(storageLocation, insecure, skipBucketVerification, proxySettings, retrySpec, concurrentConnections, kmsKeyId);
this.duration = duration;
this.bandwidth = bandwidth;
this.metadataDirective = metadataDirective == null ? MetadataDirective.COPY : metadataDirective;
this.createMissingBucket = createMissingBucket;
this.skipRefreshing = skipRefreshing;
this.dataDirs = dataDirs;
this.gcpUniformBucketLevelAccess = gcpUniformBucketLevelAccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,28 @@ private BackupOperationRequest getBackupOperationRequestForTracker(final String
final String entities,
final List<Path> dataDirs) throws Exception {
return new BackupOperationRequest(
"backup",
new StorageLocation.StorageLocationTypeConverter().convert(getStorageLocation()),
null,
null,
null,
null,
DatabaseEntities.parse(entities),
snapshotName,
false,
null,
null, // timeout
false,
false,
false,
null,
false,
null, // proxy settings
null, // retry
false, // skipRefreshing
dataDirs,
null
"backup",
new StorageLocation.StorageLocationTypeConverter().convert(getStorageLocation()),
null,
null,
null,
null,
DatabaseEntities.parse(entities),
snapshotName,
false,
null,
null, // timeout
false,
false,
false,
null,
false,
null, // proxy settings
null, // retry
false, // skipRefreshing
dataDirs,
null,
false
);
}

Expand Down