From e71312cc03adb35e6e0c829ee87248db9b069f78 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Wed, 30 May 2018 20:56:01 +0300 Subject: [PATCH] add parent_backup_link to pgBackup structure. No usage for now --- src/catalog.c | 27 +++++++++++++++++++++++++++ src/pg_probackup.h | 3 +++ src/restore.c | 1 + src/util.c | 1 + src/validate.c | 1 + 5 files changed, 33 insertions(+) diff --git a/src/catalog.c b/src/catalog.c index f5884f01..45e080c2 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -256,6 +256,8 @@ catalog_get_backup_list(time_t requested_backup_id) parray *backups = NULL; pgBackup *backup = NULL; + int i; + /* open backup instance backups directory */ date_dir = opendir(backup_instance_path); if (date_dir == NULL) @@ -283,6 +285,7 @@ catalog_get_backup_list(time_t requested_backup_id) /* read backup information from BACKUP_CONTROL_FILE */ snprintf(backup_conf_path, MAXPGPATH, "%s/%s", date_path, BACKUP_CONTROL_FILE); backup = readBackupControlFile(backup_conf_path); + backup->backup_id = backup->start_time; /* ignore corrupted backups */ if (backup) @@ -316,6 +319,30 @@ catalog_get_backup_list(time_t requested_backup_id) parray_qsort(backups, pgBackupCompareIdDesc); + /* Link incremental backups with their ancestors.*/ + for (i = 0; i < parray_num(backups); i++) + { + pgBackup *curr = parray_get(backups, i); + + int j; + + if (curr->backup_mode == BACKUP_MODE_FULL) + continue; + + for (j = i+1; j < parray_num(backups); j++) + { + pgBackup *ancestor = parray_get(backups, j); + + if (ancestor->start_time == curr->parent_backup) + { + curr->parent_backup_link = ancestor; + /* elog(INFO, "curr %s, ancestor %s j=%d", base36enc_dup(curr->start_time), + base36enc_dup(ancestor->start_time), j); */ + break; + } + } + } + return backups; err_proc: diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 30df34ce..f6eae19f 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -184,6 +184,8 @@ typedef struct pgBackupConfig int compress_level; } pgBackupConfig; +typedef struct pgBackup pgBackup; + /* Information about single backup stored in backup.conf */ typedef struct pgBackup { @@ -226,6 +228,7 @@ typedef struct pgBackup time_t parent_backup; /* Identifier of the previous backup. * Which is basic backup for this * incremental backup. */ + pgBackup *parent_backup_link; char *primary_conninfo; /* Connection parameters of the backup * in the format suitable for recovery.conf */ } pgBackup; diff --git a/src/restore.c b/src/restore.c index 69bac841..52378168 100644 --- a/src/restore.c +++ b/src/restore.c @@ -203,6 +203,7 @@ do_restore_or_validate(time_t target_backup_id, } /* If we already found dest_backup, look for full backup. */ + /* TODO Now, as we have all backups linked, we can probably get rid of that?"*/ if (dest_backup) { if (current_backup->backup_mode == BACKUP_MODE_FULL) diff --git a/src/util.c b/src/util.c index f2c84f6e..ba5647d9 100644 --- a/src/util.c +++ b/src/util.c @@ -315,6 +315,7 @@ pgBackup_init(pgBackup *backup) backup->wal_block_size = XLOG_BLCKSZ; backup->stream = false; backup->parent_backup = 0; + backup->parent_backup_link = NULL; backup->primary_conninfo = NULL; backup->server_version[0] = '\0'; } diff --git a/src/validate.c b/src/validate.c index afc7f07d..b4a1c839 100644 --- a/src/validate.c +++ b/src/validate.c @@ -283,6 +283,7 @@ do_validate_instance(void) elog(ERROR, "Failed to get backup list."); /* Valiate each backup along with its xlog files. */ + /* TODO Maybe use parent_backup_link instead of looking for backups in the list */ for (i = 0; i < parray_num(backups); i++) { pgBackup *base_full_backup = NULL;