From 635a4a53ed3a4fb2f46fa44810f35b717307a996 Mon Sep 17 00:00:00 2001 From: Arthur Zakirov Date: Wed, 24 May 2017 14:04:21 +0300 Subject: [PATCH] Added pgBackupGetPath2() --- backup.c | 4 ++-- catalog.c | 24 +++++++++++++++++++++--- pg_probackup.h | 2 ++ restore.c | 2 -- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/backup.c b/backup.c index d2158b45..3cc1027b 100644 --- a/backup.c +++ b/backup.c @@ -1676,13 +1676,13 @@ StreamLog(void *arg) ctl.synchronous = false; ctl.mark_done = false; if(ReceiveXlogStream(conn, &ctl) == false) - elog(ERROR, "Problem in recivexlog"); + elog(ERROR, "Problem in receivexlog"); } #else if(ReceiveXlogStream(conn, startpos, starttli, NULL, basedir, stop_streaming, standby_message_timeout, NULL, false, false) == false) - elog(ERROR, "Problem in recivexlog"); + elog(ERROR, "Problem in receivexlog"); #endif PQfinish(conn); diff --git a/catalog.c b/catalog.c index 4eacd474..34daf20e 100644 --- a/catalog.c +++ b/catalog.c @@ -613,14 +613,32 @@ pgBackupCompareIdDesc(const void *l, const void *r) */ void pgBackupGetPath(const pgBackup *backup, char *path, size_t len, const char *subdir) +{ + pgBackupGetPath2(backup, path, len, subdir, NULL); +} + +/* + * Construct absolute path of the backup directory. + * Append "subdir1" and "subdir2" to the backup directory. + */ +void +pgBackupGetPath2(const pgBackup *backup, char *path, size_t len, + const char *subdir1, const char *subdir2) { char *datetime; datetime = base36enc(backup->start_time); - if (subdir) - snprintf(path, len, "%s/%s/%s", backup_instance_path, datetime, subdir); + + /* If "subdir1" is NULL do not check "subdir2" */ + if (!subdir1) + snprintf(path, len, "%s/%s/%s", backup_path, BACKUPS_DIR, datetime); + else if (!subdir2) + snprintf(path, len, "%s/%s/%s/%s", backup_path, BACKUPS_DIR, datetime, subdir1); + /* "subdir1" and "subdir2" is not NULL */ else - snprintf(path, len, "%s/%s", backup_instance_path, datetime); + snprintf(path, len, "%s/%s/%s/%s/%s", backup_path, BACKUPS_DIR, + datetime, subdir1, subdir2); + free(datetime); make_native_path(path); diff --git a/pg_probackup.h b/pg_probackup.h index 15549db7..03c1ed54 100644 --- a/pg_probackup.h +++ b/pg_probackup.h @@ -338,6 +338,8 @@ extern void catalog_lock(void); extern void pgBackupWriteControl(FILE *out, pgBackup *backup); extern void pgBackupWriteBackupControlFile(pgBackup *backup); extern void pgBackupGetPath(const pgBackup *backup, char *path, size_t len, const char *subdir); +extern void pgBackupGetPath2(const pgBackup *backup, char *path, size_t len, + const char *subdir1, const char *subdir2); extern int pgBackupCreateDir(pgBackup *backup); extern void pgBackupFree(void *backup); extern int pgBackupCompareId(const void *f1, const void *f2); diff --git a/restore.c b/restore.c index babf2b84..bc8d2088 100644 --- a/restore.c +++ b/restore.c @@ -373,11 +373,9 @@ remove_deleted_files(pgBackup *backup) { parray *files; parray *files_restored; - char database_path[MAXPGPATH]; char filelist_path[MAXPGPATH]; int i; - pgBackupGetPath(backup, database_path, lengthof(database_path), DATABASE_DIR); pgBackupGetPath(backup, filelist_path, lengthof(filelist_path), DATABASE_FILE_LIST); /* Read backup's filelist using target database path as base path */ files = dir_read_file_list(pgdata, filelist_path);