Skip to content

Commit dedf25c

Browse files
Encryption settings in API for backups to fs (#28305)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c70cf1c commit dedf25c

File tree

6 files changed

+110
-15
lines changed

6 files changed

+110
-15
lines changed

ydb/core/grpc_services/rpc_import.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ class TImportRPC: public TRpcOperationRequestActor<TDerived, TEvRequest, true>,
131131
return this->Reply(StatusIds::BAD_REQUEST, TIssuesIds::DEFAULT_ERROR,
132132
"base_path must be an absolute path");
133133
}
134+
for (const auto& item : settings.items()) {
135+
if (item.destination_path().empty() && item.source_path().empty()) {
136+
return this->Reply(StatusIds::BAD_REQUEST, TIssuesIds::DEFAULT_ERROR, "Empty item is not allowed");
137+
}
138+
}
134139
}
135140

136141
this->AllocateTxId();

ydb/public/api/grpc/ydb_export_v1.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ service ExportService {
1717

1818
// Exports data to file system.
1919
// Method starts an asynchronous operation that can be cancelled while it is in progress.
20-
rpc ExportToFs(ExportToFsRequest) returns (ExportToFsResponse);
20+
rpc ExportToFs(Export.ExportToFsRequest) returns (Export.ExportToFsResponse);
2121
}

ydb/public/api/grpc/ydb_import_v1.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ service ImportService {
1818
// List objects from existing export stored in S3 bucket
1919
rpc ListObjectsInS3Export(Import.ListObjectsInS3ExportRequest) returns (Import.ListObjectsInS3ExportResponse);
2020

21+
// List objects from existing export stored in FS
22+
rpc ListObjectsInFsExport(Import.ListObjectsInFsExportRequest) returns (Import.ListObjectsInFsExportResponse);
23+
2124
// Writes data to a table.
2225
// Method accepts serialized data in the selected format and writes it non-transactionally.
2326
rpc ImportData(Import.ImportDataRequest) returns (Import.ImportDataResponse);

ydb/public/api/protos/ydb_export.proto

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ message ExportToS3Settings {
126126
// it is especially useful for custom s3 implementations
127127
bool disable_virtual_addressing = 12;
128128

129-
// Database root if not provided.
129+
// Defaults to database root if not provided.
130130
// All object names are calculated and written relative to this path.
131131
string source_path = 13;
132132

@@ -185,18 +185,23 @@ message EncryptionSettings {
185185
/// File system (FS)
186186
message ExportToFsSettings {
187187
message Item {
188-
// Database path to a table to be exported
188+
// Database path to a table/directory to be exported
189189
string source_path = 1 [(required) = true];
190190

191-
/* The tables are exported to one or more files in FS.
192-
The files are saved to the destination_path directory. */
193-
string destination_path = 2 [(required) = true];
191+
/* Tables are exported to one or more files in FS.
192+
The path begins with 'destination_path'.
193+
If not specified, actual FS path is the default `base_path` concatenated with:
194+
* The object path relative to the global `source_path` for a non-encrypted export
195+
* The anonymized path for an encrypted export
196+
*/
197+
string destination_path = 2;
194198
}
195199

196-
// Base path on FS where to write export
197-
// Path to the mounted directory in the case of NFS
200+
// Base path on FS where to write all export items
201+
// In the case of NFS, one of the directories in the path must be mounted
198202
// Must be an absolute path
199203
// Example: /mnt/exports
204+
// SchemaMapping file with the list of objects is written to this path
200205
string base_path = 1 [(required) = true];
201206

202207
// List of items to export
@@ -212,6 +217,15 @@ message ExportToFsSettings {
212217
// - zstd.
213218
// - zstd-N, where N is compression level, e.g. zstd-3.
214219
string compression = 5;
220+
221+
// Settings for data encryption.
222+
// If encryption_settings field is not specified,
223+
// the resulting data will not be encrypted.
224+
EncryptionSettings encryption_settings = 6;
225+
226+
// Defaults to database root if not provided.
227+
// All object names are calculated and written relative to this path.
228+
string source_path = 7;
215229
}
216230

217231
message ExportToFsResult {

ydb/public/api/protos/ydb_import.proto

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,23 @@ message ImportFromFsSettings {
131131
* '/scheme.pb' - object with information about scheme, indexes, etc;
132132
* '/permissions.pb' - object with information about ACL and owner;
133133
* '/metadata.json' - object with metadata about the backup.
134-
The path in FS is specified relative to base_path.
135-
Example: "my_export/table1"
134+
The FS path can be either provided explicitly (relative to base_path)
135+
Or, if the export contains the database objects list, you may specify the database object name,
136+
and the FS prefix will be looked up in the database objects list by the import procedure
136137
*/
137-
string source_path = 1 [(required) = true];
138+
string source_path = 1;
138139

139-
// Database path to a table to import to.
140-
string destination_path = 2 [(required) = true];
140+
// Database path to a database object to import the item to
141+
// Resolved relative to the default destination_path
142+
// May be omitted if the item's source_path is specified, in this case will be taken equal to it
143+
string destination_path = 2;
141144
}
142145

143146
// Base path on FS where the export is located
144-
// Path to the mounted directory in the case of NFS
147+
// In the case of NFS, one of the directories in the path must be mounted
145148
// Must be an absolute path
146149
// Example: /mnt/exports
150+
// SchemaMapping file with the list of objects is read from this path
147151
string base_path = 1 [(required) = true];
148152

149153
repeated Item items = 2; // Empty collection means import of all export objects
@@ -160,6 +164,15 @@ message ImportFromFsSettings {
160164

161165
// Skip checksum validation during import
162166
bool skip_checksum_validation = 6;
167+
168+
// Destination path to restore paths inside database
169+
// Default value is database root
170+
string destination_path = 7;
171+
172+
// Settings how data is encrypted.
173+
// If encryption_settings field is not specified,
174+
// the resulting data is considered not encrypted.
175+
Ydb.Export.EncryptionSettings encryption_settings = 8;
163176
}
164177

165178
message ImportFromFsResult {
@@ -263,6 +276,66 @@ message ListObjectsInS3ExportResponse {
263276
Ydb.Operations.Operation operation = 1;
264277
}
265278

279+
message ListObjectsInFsExportSettings {
280+
message Item {
281+
// Database object path
282+
// Recursive for directories
283+
string path = 1;
284+
}
285+
286+
string base_path = 1 [(required) = true];
287+
repeated Item items = 2;
288+
uint32 number_of_retries = 3;
289+
290+
// Settings how data is encrypted.
291+
// If encryption_settings field is not specified,
292+
// the resulting data is considered not encrypted.
293+
Ydb.Export.EncryptionSettings encryption_settings = 4;
294+
}
295+
296+
message ListObjectsInFsExportResult {
297+
message Item {
298+
/* YDB database objects in S3 are stored in one or more S3 objects (see ydb_export.proto).
299+
The S3 object name begins with a prefix, followed by:
300+
* '/data_PartNumber', where 'PartNumber' represents the index of the part, starting at zero;
301+
* '/scheme.pb' - object with information about scheme, indexes, etc;
302+
* '/permissions.pb' - object with information about ACL and owner;
303+
* '/metadata.json' - object with metadata about the backup.
304+
*/
305+
string fs_path = 1;
306+
string db_path = 2;
307+
}
308+
309+
repeated Item items = 1;
310+
311+
// This token allows you to get the next page of results for ListObjectsInFsExport requests,
312+
// if the number of results is larger than `page_size` specified in the request.
313+
// To get the next page, specify the value of `next_page_token` as a value for
314+
// the `page_token` parameter in the next ListObjectsInFsExport request. Subsequent ListObjectsInFsExport
315+
// requests will have their own `next_page_token` to continue paging through the results.
316+
string next_page_token = 2;
317+
}
318+
319+
message ListObjectsInFsExportRequest {
320+
Ydb.Operations.OperationParams operation_params = 1;
321+
ListObjectsInFsExportSettings settings = 2 [(required) = true];
322+
323+
// The maximum number of results per page that should be returned. If the number of available
324+
// results is larger than `page_size`, the service returns a `next_page_token` that can be used
325+
// to get the next page of results in subsequent ListObjectsInFsExport requests.
326+
// 0 means that server returns all objects.
327+
int64 page_size = 3 [(value) = "<= 10000"];
328+
329+
// Page token. Set `page_token` to the `next_page_token` returned by a previous ListObjectsInFsExport
330+
// request to get the next page of results.
331+
string page_token = 4;
332+
}
333+
334+
message ListObjectsInFsExportResponse {
335+
// operation.result = ListObjectsInFsExportResult
336+
Ydb.Operations.Operation operation = 1;
337+
}
338+
266339
/// Data
267340
message YdbDumpFormat {
268341
repeated string columns = 1;

ydb/services/ydb/backup_ut/fs_backup_validation_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Y_UNIT_TEST_SUITE_F(FsImportParamsValidationTest, TFsBackupParamsValidationTestF
292292
UNIT_ASSERT_VALUES_EQUAL_C(res.Status().GetStatus(), NYdb::EStatus::BAD_REQUEST,
293293
res.Status().GetIssues().ToString());
294294
UNIT_ASSERT_STRING_CONTAINS_C(res.Status().GetIssues().ToString(),
295-
"source_path is required but not set",
295+
"Empty item is not allowed",
296296
res.Status().GetIssues().ToString());
297297
}
298298
}

0 commit comments

Comments
 (0)