mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-02-03 14:01:57 +02:00
Use join_path_components() if possible.
git-svn-id: http://pg-rman.googlecode.com/svn/trunk@27 182aca00-e38e-11de-a668-6fd11605f5ce
This commit is contained in:
parent
182444045c
commit
e3b9fd4e16
6
backup.c
6
backup.c
@ -314,8 +314,7 @@ do_backup_arclog(parray *backup_list)
|
||||
* We do this after create file list, because copy_file() update
|
||||
* pgFile->write_size to actual size.
|
||||
*/
|
||||
snprintf(timeline_dir, lengthof(timeline_dir), "%s/%s", backup_path,
|
||||
TIMELINE_HISTORY_DIR);
|
||||
join_path_components(timeline_dir, backup_path, TIMELINE_HISTORY_DIR);
|
||||
for (i = 0; i < parray_num(files); i++)
|
||||
{
|
||||
pgFile *file = (pgFile *) parray_get(files, i);
|
||||
@ -875,8 +874,7 @@ backup_files(const char *from_root,
|
||||
{
|
||||
char dirpath[MAXPGPATH];
|
||||
|
||||
snprintf(dirpath, lengthof(dirpath), "%s/%s", to_root,
|
||||
file->path + strlen(from_root) + 1);
|
||||
join_path_components(dirpath, to_root, file->path + strlen(from_root) + 1);
|
||||
if (!check)
|
||||
dir_create_dir(dirpath, DIR_PERMISSION);
|
||||
if (verbose)
|
||||
|
51
catalog.c
51
catalog.c
@ -37,8 +37,7 @@ catalog_lock(void)
|
||||
int ret;
|
||||
char id_path[MAXPGPATH];
|
||||
|
||||
snprintf(id_path, lengthof(id_path), "%s/%s", backup_path,
|
||||
PG_RMAN_INI_FILE);
|
||||
join_path_components(id_path, backup_path, PG_RMAN_INI_FILE);
|
||||
lock_fd = open(id_path, O_RDWR);
|
||||
if (lock_fd == -1)
|
||||
elog(errno == ENOENT ? ERROR_CORRUPTED : ERROR_SYSTEM,
|
||||
@ -81,8 +80,8 @@ catalog_unlock(void)
|
||||
pgBackup *
|
||||
catalog_get_backup(time_t timestamp)
|
||||
{
|
||||
pgBackup tmp;
|
||||
char ini_path[MAXPGPATH];
|
||||
pgBackup tmp;
|
||||
char ini_path[MAXPGPATH];
|
||||
|
||||
tmp.start_time = timestamp;
|
||||
pgBackupGetPath(&tmp, ini_path, lengthof(ini_path), BACKUP_INI_FILE);
|
||||
@ -120,18 +119,18 @@ parray *
|
||||
catalog_get_backup_list(const pgBackupRange *range)
|
||||
{
|
||||
const pgBackupRange range_all = { 0, 0 };
|
||||
DIR *date_dir = NULL;
|
||||
struct dirent *date_ent = NULL;
|
||||
DIR *time_dir = NULL;
|
||||
struct dirent *time_ent = NULL;
|
||||
char date_path[MAXPGPATH];
|
||||
parray *backups = NULL;
|
||||
pgBackup *backup = NULL;
|
||||
struct tm *tm;
|
||||
char begin_date[100];
|
||||
char begin_time[100];
|
||||
char end_date[100];
|
||||
char end_time[100];
|
||||
DIR *date_dir = NULL;
|
||||
struct dirent *date_ent = NULL;
|
||||
DIR *time_dir = NULL;
|
||||
struct dirent *time_ent = NULL;
|
||||
char date_path[MAXPGPATH];
|
||||
parray *backups = NULL;
|
||||
pgBackup *backup = NULL;
|
||||
struct tm *tm;
|
||||
char begin_date[100];
|
||||
char begin_time[100];
|
||||
char end_date[100];
|
||||
char end_time[100];
|
||||
|
||||
if (range == NULL)
|
||||
range = &range_all;
|
||||
@ -172,7 +171,7 @@ catalog_get_backup_list(const pgBackupRange *range)
|
||||
continue;
|
||||
|
||||
/* open subdirectory (date directory) and search time directory */
|
||||
snprintf(date_path, MAXPGPATH, "%s/%s", backup_path, date_ent->d_name);
|
||||
join_path_components(date_path, backup_path, date_ent->d_name);
|
||||
time_dir = opendir(date_path);
|
||||
if (time_dir == NULL)
|
||||
{
|
||||
@ -291,8 +290,8 @@ catalog_get_last_arclog_backup(parray *backup_list)
|
||||
pgBackup *
|
||||
catalog_get_last_srvlog_backup(parray *backup_list)
|
||||
{
|
||||
int i;
|
||||
pgBackup *backup = NULL;
|
||||
int i;
|
||||
pgBackup *backup = NULL;
|
||||
|
||||
/* backup_list is sorted in order of descending ID */
|
||||
for (i = 0; i < parray_num(backup_list); i++)
|
||||
@ -311,9 +310,9 @@ catalog_get_last_srvlog_backup(parray *backup_list)
|
||||
int
|
||||
pgBackupCreateDir(pgBackup *backup)
|
||||
{
|
||||
int i;
|
||||
char path[MAXPGPATH];
|
||||
char *subdirs[] = { DATABASE_DIR, ARCLOG_DIR, SRVLOG_DIR, NULL };
|
||||
int i;
|
||||
char path[MAXPGPATH];
|
||||
char *subdirs[] = { DATABASE_DIR, ARCLOG_DIR, SRVLOG_DIR, NULL };
|
||||
|
||||
pgBackupGetPath(backup, path, lengthof(path), NULL);
|
||||
dir_create_dir(path, DIR_PERMISSION);
|
||||
@ -377,8 +376,8 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
|
||||
void
|
||||
pgBackupWriteIni(pgBackup *backup)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char ini_path[MAXPGPATH];
|
||||
FILE *fp = NULL;
|
||||
char ini_path[MAXPGPATH];
|
||||
|
||||
pgBackupGetPath(backup, ini_path, lengthof(ini_path), BACKUP_INI_FILE);
|
||||
fp = fopen(ini_path, "wt");
|
||||
@ -561,8 +560,8 @@ pgBackupCompareIdDesc(const void *l, const void *r)
|
||||
void
|
||||
pgBackupGetPath(const pgBackup *backup, char *path, size_t len, const char *subdir)
|
||||
{
|
||||
char datetime[20];
|
||||
struct tm *tm;
|
||||
char datetime[20];
|
||||
struct tm *tm;
|
||||
|
||||
/* generate $BACKUP_PATH/date/time path */
|
||||
tm = localtime(&backup->start_time);
|
||||
|
9
data.c
9
data.c
@ -307,8 +307,7 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
if (check)
|
||||
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
|
||||
else
|
||||
snprintf(to_path, lengthof(to_path), "%s/%s",
|
||||
to_root, file->path + strlen(from_root) + 1);
|
||||
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
|
||||
out = fopen(to_path, "w");
|
||||
if (out == NULL)
|
||||
{
|
||||
@ -594,8 +593,7 @@ restore_data_file(const char *from_root,
|
||||
* modified pages for incremental restore. If the file is not exists,
|
||||
* re-open it with "w" to create an empty file.
|
||||
*/
|
||||
snprintf(to_path, lengthof(to_path), "%s/%s", to_root,
|
||||
file->path + strlen(from_root) + 1);
|
||||
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
|
||||
out = fopen(to_path, "r+");
|
||||
if (out == NULL && errno == ENOENT)
|
||||
out = fopen(to_path, "w");
|
||||
@ -783,8 +781,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
if (check)
|
||||
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
|
||||
else
|
||||
snprintf(to_path, lengthof(to_path), "%s/%s", to_root,
|
||||
file->path + strlen(from_root) + 1);
|
||||
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
|
||||
out = fopen(to_path, "w");
|
||||
if (out == NULL)
|
||||
{
|
||||
|
16
dir.c
16
dir.c
@ -246,7 +246,7 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
|
||||
|
||||
strncpy(dname, file->path, lengthof(dname));
|
||||
dnamep = dirname(dname);
|
||||
snprintf(absolute, lengthof(absolute), "%s/%s", dname, linked);
|
||||
join_path_components(absolute, dname, linked);
|
||||
file = pgFileNew(absolute, omit_symlink);
|
||||
}
|
||||
else
|
||||
@ -329,7 +329,7 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
|
||||
strcmp(dent->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
snprintf(child, lengthof(child), "%s/%s", file->path, dent->d_name);
|
||||
join_path_components(child, file->path, dent->d_name);
|
||||
dir_list_file(files, child, exclude, omit_symlink, true);
|
||||
}
|
||||
if (errno && errno != ENOENT)
|
||||
@ -438,9 +438,9 @@ dir_print_file_list(FILE *out, const parray *files, const char *root)
|
||||
parray *
|
||||
dir_read_file_list(const char *root, const char *file_txt)
|
||||
{
|
||||
FILE *fp;
|
||||
FILE *fp;
|
||||
parray *files;
|
||||
char buf[MAXPGPATH * 2];
|
||||
char buf[MAXPGPATH * 2];
|
||||
|
||||
fp = fopen(file_txt, "rt");
|
||||
if (fp == NULL)
|
||||
@ -508,9 +508,8 @@ dir_read_file_list(const char *root, const char *file_txt)
|
||||
void
|
||||
dir_copy_files(const char *from_root, const char *to_root)
|
||||
{
|
||||
int i;
|
||||
parray *files;
|
||||
files = parray_new();
|
||||
int i;
|
||||
parray *files = parray_new();
|
||||
|
||||
/* don't copy root directory */
|
||||
dir_list_file(files, from_root, NULL, true, false);
|
||||
@ -522,8 +521,7 @@ dir_copy_files(const char *from_root, const char *to_root)
|
||||
if (S_ISDIR(file->mode))
|
||||
{
|
||||
char to_path[MAXPGPATH];
|
||||
snprintf(to_path, lengthof(to_path), "%s/%s", to_root,
|
||||
file->path + strlen(from_root) + 1);
|
||||
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
|
||||
if (verbose && !check)
|
||||
printf(_("create directory \"%s\"\n"),
|
||||
file->path + strlen(from_root) + 1);
|
||||
|
12
init.c
12
init.c
@ -32,7 +32,7 @@ do_init(void)
|
||||
dir_create_dir(backup_path, DIR_PERMISSION);
|
||||
|
||||
/* create directories for backup of online files */
|
||||
snprintf(path, lengthof(path), "%s/%s", backup_path, RESTORE_WORK_DIR);
|
||||
join_path_components(path, backup_path, RESTORE_WORK_DIR);
|
||||
dir_create_dir(path, DIR_PERMISSION);
|
||||
snprintf(path, lengthof(path), "%s/%s/%s", backup_path, RESTORE_WORK_DIR,
|
||||
PG_XLOG_DIR);
|
||||
@ -42,18 +42,18 @@ do_init(void)
|
||||
dir_create_dir(path, DIR_PERMISSION);
|
||||
|
||||
/* create directory for timeline history files */
|
||||
snprintf(path, lengthof(path), "%s/%s", backup_path, TIMELINE_HISTORY_DIR);
|
||||
join_path_components(path, backup_path, TIMELINE_HISTORY_DIR);
|
||||
dir_create_dir(path, DIR_PERMISSION);
|
||||
|
||||
/* read postgresql.conf */
|
||||
if (pgdata)
|
||||
{
|
||||
snprintf(path, lengthof(path), "%s/%s", pgdata, "postgresql.conf");
|
||||
join_path_components(path, pgdata, "postgresql.conf");
|
||||
parse_postgresql_conf(path, &log_directory, &archive_command);
|
||||
}
|
||||
|
||||
/* create pg_rman.ini */
|
||||
snprintf(path, lengthof(path), "%s/%s", backup_path, PG_RMAN_INI_FILE);
|
||||
join_path_components(path, backup_path, PG_RMAN_INI_FILE);
|
||||
fp = fopen(path, "wt");
|
||||
if (fp == NULL)
|
||||
elog(ERROR_SYSTEM, _("can't create pg_rman.ini: %s"), strerror(errno));
|
||||
@ -112,14 +112,14 @@ do_init(void)
|
||||
else
|
||||
{
|
||||
srvlog_path = pgut_malloc(MAXPGPATH);
|
||||
snprintf(srvlog_path, MAXPGPATH, "%s/%s", pgdata, log_directory);
|
||||
join_path_components(srvlog_path, pgdata, log_directory);
|
||||
}
|
||||
}
|
||||
else if (pgdata)
|
||||
{
|
||||
/* default: log_directory = 'pg_log' */
|
||||
srvlog_path = pgut_malloc(MAXPGPATH);
|
||||
snprintf(srvlog_path, MAXPGPATH, "%s/%s", pgdata, "pg_log");
|
||||
join_path_components(srvlog_path, pgdata, "pg_log");
|
||||
}
|
||||
}
|
||||
if (srvlog_path)
|
||||
|
@ -140,7 +140,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
char path[MAXPGPATH];
|
||||
|
||||
snprintf(path, lengthof(path), "%s/%s", backup_path, PG_RMAN_INI_FILE);
|
||||
join_path_components(path, backup_path, PG_RMAN_INI_FILE);
|
||||
pgut_readopt(path, options, ERROR_ARGS);
|
||||
}
|
||||
|
||||
|
12
restore.c
12
restore.c
@ -128,8 +128,7 @@ do_restore(const char *target_time,
|
||||
* restore timeline history files and get timeline branches can reach
|
||||
* recovery target point.
|
||||
*/
|
||||
snprintf(timeline_dir, lengthof(timeline_dir), "%s/%s", backup_path,
|
||||
TIMELINE_HISTORY_DIR);
|
||||
join_path_components(timeline_dir, backup_path, TIMELINE_HISTORY_DIR);
|
||||
if (verbose && !check)
|
||||
printf(_("restoring timeline history files\n"));
|
||||
dir_copy_files(timeline_dir, arclog_path);
|
||||
@ -254,7 +253,7 @@ base_backup_found:
|
||||
if (verbose)
|
||||
printf(_("searching online WAL...\n"));
|
||||
|
||||
snprintf(xlogpath, lengthof(xlogpath), "%s/%s", pgdata, PG_XLOG_DIR);
|
||||
join_path_components(xlogpath, pgdata, PG_XLOG_DIR);
|
||||
search_next_wal(xlogpath, &needId, &needSeg, timelines);
|
||||
|
||||
if (verbose)
|
||||
@ -489,8 +488,7 @@ restore_archive_logs(pgBackup *backup)
|
||||
elog(ERROR_INTERRUPTED, _("interrupted during restore WAL"));
|
||||
|
||||
/* print progress */
|
||||
snprintf(path, lengthof(path), "%s/%s", arclog_path,
|
||||
file->path + strlen(base_path) + 1);
|
||||
join_path_components(path, arclog_path, file->path + strlen(base_path) + 1);
|
||||
if (verbose && !check)
|
||||
printf(_("(%d/%lu) %s "), i + 1, (unsigned long) parray_num(files),
|
||||
file->path + strlen(base_path) + 1);
|
||||
@ -669,7 +667,7 @@ restore_online_files(void)
|
||||
else if(S_ISREG(file->mode))
|
||||
{
|
||||
char to_root[MAXPGPATH];
|
||||
snprintf(to_root, lengthof(to_root), "%s/%s", pgdata, PG_XLOG_DIR);
|
||||
join_path_components(to_root, pgdata, PG_XLOG_DIR);
|
||||
if (verbose && !check)
|
||||
printf(_("restore \"%s\"\n"),
|
||||
file->path + strlen(root_backup) + 1);
|
||||
@ -940,7 +938,7 @@ search_next_wal(const char *path, uint32 *needId, uint32 *needSeg, parray *timel
|
||||
pgTimeLine *timeline = (pgTimeLine *) parray_get(timelines, i);
|
||||
|
||||
XLogFileName(xlogfname, timeline->tli, *needId, *needSeg);
|
||||
snprintf(xlogpath, lengthof(xlogpath), "%s/%s", path, xlogfname);
|
||||
join_path_components(xlogpath, path, xlogfname);
|
||||
|
||||
if (stat(xlogpath, &st) == 0)
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user