mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2026-06-21 01:34:15 +02:00
Revert "PBCKP-415 use pio for catalog_get_backup_list"
This reverts commit f0215bbcc4.
This commit is contained in:
+57
-23
@@ -802,6 +802,27 @@ pgBackupGetBackupMode(pgBackup *backup, bool show_color)
|
||||
return backupModes[backup->backup_mode];
|
||||
}
|
||||
|
||||
static bool
|
||||
IsDir(const char *dirpath, const char *entry, fio_location location)
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
char path[MAXPGPATH];
|
||||
pio_stat_t st;
|
||||
err_i err;
|
||||
|
||||
join_path_components(path, dirpath, entry);
|
||||
|
||||
st = $i(pioStat, pioDriveForLocation(location),
|
||||
.path = path, .follow_symlink = false, .err = &err);
|
||||
if ($haserr(err))
|
||||
{
|
||||
ft_logerr(FT_WARNING, $errmsg(err), "IsDir");
|
||||
return false;
|
||||
}
|
||||
|
||||
return st.pst_kind == PIO_KIND_DIRECTORY;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create list of instances in given backup catalog.
|
||||
*
|
||||
@@ -872,35 +893,35 @@ catalog_get_instance_list(CatalogState *catalogState)
|
||||
parray *
|
||||
catalog_get_backup_list(InstanceState *instanceState, time_t requested_backup_id)
|
||||
{
|
||||
DIR *data_dir = NULL;
|
||||
struct dirent *data_ent = NULL;
|
||||
parray *backups = NULL;
|
||||
parray *files = NULL;
|
||||
int i;
|
||||
|
||||
files = parray_new();
|
||||
backup_list_dir(files, instanceState->instance_backup_subdir_path);
|
||||
/* open backup instance backups directory */
|
||||
data_dir = fio_opendir(FIO_BACKUP_HOST, instanceState->instance_backup_subdir_path);
|
||||
if (data_dir == NULL)
|
||||
{
|
||||
elog(WARNING, "cannot open directory \"%s\": %s", instanceState->instance_backup_subdir_path,
|
||||
strerror(errno));
|
||||
goto err_proc;
|
||||
}
|
||||
|
||||
/* scan the directory and list backups */
|
||||
backups = parray_new();
|
||||
for(i = 0; i < parray_num(files); ++i)
|
||||
for (; (data_ent = fio_readdir(data_dir)) != NULL; errno = 0)
|
||||
{
|
||||
char backup_conf_path[MAXPGPATH];
|
||||
char data_path[MAXPGPATH];
|
||||
char backup_dir_name[MAXPGPATH];
|
||||
pgFile *file = (pgFile *) parray_get(files, i);
|
||||
pgBackup *backup = NULL;
|
||||
char *slash;
|
||||
|
||||
if (strcmp(file->name, BACKUP_CONTROL_FILE) != 0)
|
||||
/* skip not-directory entries and hidden entries */
|
||||
if (!IsDir(instanceState->instance_backup_subdir_path, data_ent->d_name, FIO_BACKUP_HOST)
|
||||
|| data_ent->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
slash = strchr(file->rel_path, '/');
|
||||
if(!slash)
|
||||
continue;
|
||||
memcpy(backup_dir_name, file->rel_path, slash - file->rel_path);
|
||||
backup_dir_name[slash - file->rel_path] = 0;
|
||||
|
||||
/* open subdirectory of specific backup */
|
||||
join_path_components(data_path, instanceState->instance_backup_subdir_path, backup_dir_name);
|
||||
join_path_components(data_path, instanceState->instance_backup_subdir_path, data_ent->d_name);
|
||||
|
||||
/* read backup information from BACKUP_CONTROL_FILE */
|
||||
join_path_components(backup_conf_path, data_path, BACKUP_CONTROL_FILE);
|
||||
@@ -910,12 +931,12 @@ catalog_get_backup_list(InstanceState *instanceState, time_t requested_backup_id
|
||||
{
|
||||
backup = pgut_new0(pgBackup);
|
||||
pgBackupInit(backup, instanceState->backup_location);
|
||||
backup->start_time = base36dec(backup_dir_name);
|
||||
backup->start_time = base36dec(data_ent->d_name);
|
||||
/* XXX BACKUP_ID change it when backup_id wouldn't match start_time */
|
||||
Assert(backup->backup_id == 0 || backup->backup_id == backup->start_time);
|
||||
backup->backup_id = backup->start_time;
|
||||
}
|
||||
else if (strcmp(backup_id_of(backup), backup_dir_name) != 0)
|
||||
else if (strcmp(backup_id_of(backup), data_ent->d_name) != 0)
|
||||
{
|
||||
/* TODO there is no such guarantees */
|
||||
elog(WARNING, "backup ID in control file \"%s\" doesn't match name of the backup folder \"%s\"",
|
||||
@@ -923,6 +944,7 @@ catalog_get_backup_list(InstanceState *instanceState, time_t requested_backup_id
|
||||
}
|
||||
|
||||
backup->root_dir = pgut_strdup(data_path);
|
||||
|
||||
backup->database_dir = pgut_malloc(MAXPGPATH);
|
||||
join_path_components(backup->database_dir, backup->root_dir, DATABASE_DIR);
|
||||
|
||||
@@ -939,15 +961,16 @@ catalog_get_backup_list(InstanceState *instanceState, time_t requested_backup_id
|
||||
parray_append(backups, backup);
|
||||
}
|
||||
|
||||
parray_walk(files, pgFileFree);
|
||||
parray_free(files);
|
||||
|
||||
if (parray_num(backups) == 0)
|
||||
if (errno)
|
||||
{
|
||||
elog(WARNING, "Cannot find any backups in \"%s\"",
|
||||
instanceState->instance_backup_subdir_path);
|
||||
elog(WARNING, "Cannot read backup root directory \"%s\": %s",
|
||||
instanceState->instance_backup_subdir_path, strerror(errno));
|
||||
goto err_proc;
|
||||
}
|
||||
|
||||
fio_closedir(data_dir);
|
||||
data_dir = NULL;
|
||||
|
||||
parray_qsort(backups, pgBackupCompareIdDesc);
|
||||
|
||||
/* Link incremental backups with their ancestors.*/
|
||||
@@ -968,6 +991,17 @@ catalog_get_backup_list(InstanceState *instanceState, time_t requested_backup_id
|
||||
}
|
||||
|
||||
return backups;
|
||||
|
||||
err_proc:
|
||||
if (data_dir)
|
||||
fio_closedir(data_dir);
|
||||
if (backups)
|
||||
parray_walk(backups, pgBackupFree);
|
||||
parray_free(backups);
|
||||
|
||||
elog(ERROR, "Failed to get backup list");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user