Skip to content

Commit 34d7e97

Browse files
Amr-Shamsjesperpedersen
authored andcommitted
[pgmoneta#1089] chain verify for the restore workflow of s3
Signed-off-by: Amr-Shams <amr.shams2015.as@gmail.com>
1 parent 82a4dec commit 34d7e97

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

src/libpgmoneta/s3.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,12 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
326326
struct timespec start_t;
327327
struct timespec end_t;
328328
double total_seconds;
329-
// struct json* response = NULL;
329+
char* base_dir = NULL;
330330
struct art* nodes = NULL;
331331
struct workflow* workflow = NULL;
332332
struct main_configuration* config;
333+
struct backup* backup = NULL;
334+
char* local_root = NULL;
333335

334336
config = (struct main_configuration*)shmem;
335337

@@ -378,6 +380,31 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
378380
pgmoneta_log_error("S3 restore: workflow failed for %s", config->common.servers[server].name);
379381
goto error;
380382
}
383+
pgmoneta_workflow_destroy(workflow);
384+
base_dir = pgmoneta_get_server_backup(server);
385+
local_root = pgmoneta_get_server_backup_identifier(server, prefix);
386+
if (pgmoneta_art_insert(nodes, NODE_TARGET_BASE, (uintptr_t)local_root, ValueString))
387+
{
388+
pgmoneta_log_error("S3 restore: could not add backup dir to art");
389+
goto error;
390+
}
391+
if (pgmoneta_art_insert(nodes, USER_FILES, (uintptr_t)NODE_ALL, ValueString))
392+
{
393+
pgmoneta_log_error("S3 restore: could not add base dir to art");
394+
goto error;
395+
}
396+
397+
if (pgmoneta_load_info(base_dir, prefix, &backup))
398+
{
399+
pgmoneta_log_error("S3 restore: could not load info for %s", config->common.servers[server].name);
400+
goto error;
401+
}
402+
workflow = pgmoneta_workflow_create(WORKFLOW_TYPE_VERIFY, backup);
403+
if (pgmoneta_workflow_execute(workflow, nodes, &en, &ec))
404+
{
405+
pgmoneta_log_error("S3 restore: workflow failed for %s", config->common.servers[server].name);
406+
goto error;
407+
}
381408

382409
#ifdef HAVE_FREEBSD
383410
clock_gettime(CLOCK_MONOTONIC_FAST, &end_t);
@@ -402,6 +429,9 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
402429

403430
pgmoneta_disconnect(client_fd);
404431
pgmoneta_stop_logging();
432+
free(backup);
433+
free(base_dir);
434+
free(local_root);
405435
exit(0);
406436

407437
error:
@@ -414,8 +444,14 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
414444
pgmoneta_art_destroy(nodes);
415445
pgmoneta_workflow_destroy(workflow);
416446
free(elapsed);
417-
447+
free(base_dir);
448+
free(backup);
449+
if (local_root != NULL)
450+
{
451+
pgmoneta_delete_directory(local_root);
452+
}
418453
pgmoneta_disconnect(client_fd);
419454
pgmoneta_stop_logging();
455+
free(local_root);
420456
exit(1);
421457
}

0 commit comments

Comments
 (0)