Skip to content

Commit 14781dd

Browse files
committed
Merge branch 'REL_2_6' into release_2_6-pbckp-232
2 parents 249876a + f514488 commit 14781dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1759
-808
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ PROGRAM := pg_probackup
3333
# pg_probackup sources
3434
OBJS := src/utils/configuration.o src/utils/json.o src/utils/logger.o \
3535
src/utils/parray.o src/utils/pgut.o src/utils/thread.o src/utils/remote.o src/utils/file.o
36-
OBJS += src/fu_util/impl/ft_impl.o src/fu_util/impl/fo_impl.o
3736
OBJS += src/archive.o src/backup.o src/catalog.o src/checkdb.o src/configure.o src/data.o \
3837
src/delete.o src/dir.o src/fetch.o src/help.o src/init.o src/merge.o \
3938
src/parsexlog.o src/ptrack.o src/pg_probackup.o src/restore.o src/show.o src/stream.o \
@@ -52,6 +51,8 @@ BORROWED_C_SRC := \
5251
src/bin/pg_basebackup/streamutil.c \
5352
src/bin/pg_basebackup/walmethods.c
5453

54+
OBJS += src/fu_util/impl/ft_impl.o src/fu_util/impl/fo_impl.o
55+
5556
BORROW_DIR := src/borrowed
5657
BORROWED_H := $(addprefix $(BORROW_DIR)/, $(notdir $(BORROWED_H_SRC)))
5758
BORROWED_C := $(addprefix $(BORROW_DIR)/, $(notdir $(BORROWED_C_SRC)))

doc/pgprobackup.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,6 +3958,7 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
39583958
[--restore-command=<replaceable>cmdline</replaceable>]
39593959
[--primary-conninfo=<replaceable>primary_conninfo</replaceable>]
39603960
[-S | --primary-slot-name=<replaceable>slot_name</replaceable>]
3961+
[-X <replaceable>wal_dir</replaceable> | --waldir=<replaceable>wal_dir</replaceable>]
39613962
[<replaceable>recovery_target_options</replaceable>] [<replaceable>logging_options</replaceable>] [<replaceable>remote_options</replaceable>]
39623963
[<replaceable>partial_restore_options</replaceable>] [<replaceable>remote_wal_archive_options</replaceable>]
39633964
</programlisting>
@@ -4125,6 +4126,17 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
41254126
</para>
41264127
</listitem>
41274128
</varlistentry>
4129+
4130+
<varlistentry>
4131+
<term><option>-X <replaceable>wal_dir</replaceable></option></term>
4132+
<term><option>--waldir=<replaceable>wal_dir</replaceable></option></term>
4133+
<listitem>
4134+
<para>
4135+
Specifies the directory where WAL should be stored.
4136+
</para>
4137+
</listitem>
4138+
</varlistentry>
4139+
41284140
</variablelist>
41294141
</para>
41304142
<para>
@@ -5150,6 +5162,60 @@ pg_probackup catchup -b <replaceable>catchup_mode</replaceable>
51505162
</varlistentry>
51515163

51525164
<varlistentry>
5165+
<term><option>--log-format-console=<replaceable>log_format</replaceable></option></term>
5166+
<listitem>
5167+
<para>
5168+
Defines the format of the console log. Only set from the command line. Note that you cannot
5169+
specify this option in the <filename>pg_probackup.conf</filename> configuration file through
5170+
the <xref linkend="pbk-set-config"/> command and that the <xref linkend="pbk-backup"/>
5171+
command also treats this option specified in the configuration file as an error.
5172+
Possible values are:
5173+
5174+
<itemizedlist spacing="compact">
5175+
<listitem>
5176+
<para>
5177+
<literal>plain</literal> — sets the plain-text format of the console log.
5178+
</para>
5179+
</listitem>
5180+
<listitem>
5181+
<para>
5182+
<literal>json</literal> — sets the <acronym>JSON</acronym> format of the console log.
5183+
</para>
5184+
</listitem>
5185+
</itemizedlist>
5186+
</para>
5187+
<para>
5188+
Default: <literal>plain</literal>
5189+
</para>
5190+
</listitem>
5191+
</varlistentry>
5192+
5193+
<varlistentry>
5194+
<term><option>--log-format-file=<replaceable>log_format</replaceable></option></term>
5195+
<listitem>
5196+
<para>
5197+
Defines the format of log files used. Possible values are:
5198+
5199+
<itemizedlist spacing="compact">
5200+
<listitem>
5201+
<para>
5202+
<literal>plain</literal> — sets the plain-text format of log files.
5203+
</para>
5204+
</listitem>
5205+
<listitem>
5206+
<para>
5207+
<literal>json</literal> — sets the <acronym>JSON</acronym> format of log files.
5208+
</para>
5209+
</listitem>
5210+
</itemizedlist>
5211+
</para>
5212+
<para>
5213+
Default: <literal>plain</literal>
5214+
</para>
5215+
</listitem>
5216+
</varlistentry>
5217+
5218+
<varlistentry>
51535219
<term><option>--log-rotation-size=<replaceable>log_rotation_size</replaceable></option></term>
51545220
<listitem>
51555221
<para>
@@ -6021,6 +6087,8 @@ archive-timeout = 5min
60216087
# Logging parameters
60226088
log-level-console = INFO
60236089
log-level-file = OFF
6090+
log-format-console = PLAIN
6091+
log-format-file = PLAIN
60246092
log-filename = pg_probackup.log
60256093
log-rotation-size = 0
60266094
log-rotation-age = 0

src/archive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
347347
canonicalize_path(wal_file_ready);
348348
canonicalize_path(wal_file_done);
349349
/* It is ok to rename status file in archive_status directory */
350-
elog(VERBOSE, "Rename \"%s\" to \"%s\"", wal_file_ready, wal_file_done);
350+
elog(LOG, "Rename \"%s\" to \"%s\"", wal_file_ready, wal_file_done);
351351

352352
/* do not error out, if rename failed */
353353
if (fio_rename(FIO_DB_HOST, wal_file_ready, wal_file_done) < 0)
@@ -502,7 +502,7 @@ push_file_internal(const char *wal_file_name, const char *pg_xlog_dir,
502502
elog(ERROR, "Temp WAL: %s", $errmsg(err));
503503

504504
part_opened:
505-
elog(VERBOSE, "Temp WAL file successfully created: \"%s\"", to_fullpath_part);
505+
elog(LOG, "Temp WAL file successfully created: \"%s\"", to_fullpath_part);
506506

507507
if ($i(pioExists, backup_drive, to_fullpath, &err))
508508
{
@@ -872,7 +872,7 @@ do_archive_get(InstanceState *instanceState, InstanceConfig *instance, const cha
872872
if (get_wal_file(wal_file_name, backup_wal_file_path, absolute_wal_file_path, false))
873873
{
874874
fail_count = 0;
875-
elog(INFO, "pg_probackup archive-get copied WAL file %s", wal_file_name);
875+
elog(LOG, "pg_probackup archive-get copied WAL file %s", wal_file_name);
876876
n_fetched++;
877877
break;
878878
}

src/backup.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
113113
char pretty_time[20];
114114
char pretty_bytes[20];
115115

116-
elog(LOG, "Database backup start");
116+
elog(INFO, "Database backup start");
117117
if(current.external_dir_str)
118118
{
119119
external_dirs = make_external_directory_list(current.external_dir_str,
@@ -329,11 +329,11 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
329329
/* Extract information about files in backup_list parsing their names:*/
330330
parse_filelist_filenames(backup_files_list, instance_config.pgdata);
331331

332-
elog(LOG, "Current Start LSN: %X/%X, TLI: %X",
332+
elog(INFO, "Current Start LSN: %X/%X, TLI: %X",
333333
(uint32) (current.start_lsn >> 32), (uint32) (current.start_lsn),
334334
current.tli);
335335
if (current.backup_mode != BACKUP_MODE_FULL)
336-
elog(LOG, "Parent Start LSN: %X/%X, TLI: %X",
336+
elog(INFO, "Parent Start LSN: %X/%X, TLI: %X",
337337
(uint32) (prev_backup->start_lsn >> 32), (uint32) (prev_backup->start_lsn),
338338
prev_backup->tli);
339339

@@ -405,7 +405,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
405405
else
406406
join_path_components(dirpath, current.database_dir, file->rel_path);
407407

408-
elog(VERBOSE, "Create directory '%s'", dirpath);
408+
elog(LOG, "Create directory '%s'", dirpath);
409409
fio_mkdir(FIO_BACKUP_HOST, dirpath, DIR_PERMISSION, false);
410410
}
411411

@@ -666,7 +666,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
666666
nodeInfo->checksum_version = current.checksum_version;
667667

668668
if (current.checksum_version)
669-
elog(LOG, "This PostgreSQL instance was initialized with data block checksums. "
669+
elog(INFO, "This PostgreSQL instance was initialized with data block checksums. "
670670
"Data block corruption will be detected");
671671
else
672672
elog(WARNING, "This PostgreSQL instance was initialized without data block checksums. "
@@ -688,7 +688,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
688688
*/
689689
int
690690
do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
691-
bool no_validate, bool no_sync, bool backup_logs)
691+
bool no_validate, bool no_sync, bool backup_logs, time_t start_time)
692692
{
693693
PGconn *backup_conn = NULL;
694694
PGNodeInfo nodeInfo;
@@ -703,7 +703,7 @@ do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
703703
current.external_dir_str = instance_config.external_dir_str;
704704

705705
/* Create backup directory and BACKUP_CONTROL_FILE */
706-
pgBackupCreateDir(&current, instanceState->instance_backup_subdir_path);
706+
pgBackupCreateDir(&current, instanceState, start_time);
707707

708708
if (!instance_config.pgdata)
709709
elog(ERROR, "required parameter not specified: PGDATA "
@@ -1473,7 +1473,7 @@ wait_wal_and_calculate_stop_lsn(const char *xlog_path, XLogRecPtr stop_lsn, pgBa
14731473
stop_lsn_exists = true;
14741474
}
14751475

1476-
elog(LOG, "stop_lsn: %X/%X",
1476+
elog(INFO, "stop_lsn: %X/%X",
14771477
(uint32) (stop_lsn >> 32), (uint32) (stop_lsn));
14781478

14791479
/*
@@ -1811,15 +1811,15 @@ pg_stop_backup(InstanceState *instanceState, pgBackup *backup, PGconn *pg_startb
18111811

18121812
backup->recovery_xid = stop_backup_result.snapshot_xid;
18131813

1814-
elog(LOG, "Getting the Recovery Time from WAL");
1814+
elog(INFO, "Getting the Recovery Time from WAL");
18151815

18161816
/* iterate over WAL from stop_backup lsn to start_backup lsn */
18171817
if (!read_recovery_info(xlog_path, backup->tli,
18181818
instance_config.xlog_seg_size,
18191819
backup->start_lsn, backup->stop_lsn,
18201820
&backup->recovery_time))
18211821
{
1822-
elog(LOG, "Failed to find Recovery Time in WAL, forced to trust current_timestamp");
1822+
elog(INFO, "Failed to find Recovery Time in WAL, forced to trust current_timestamp");
18231823
backup->recovery_time = stop_backup_result.invocation_time;
18241824
}
18251825

@@ -1901,9 +1901,8 @@ backup_files(void *arg)
19011901
if (interrupted || thread_interrupted)
19021902
elog(ERROR, "interrupted during backup");
19031903

1904-
if (progress)
1905-
elog(INFO, "Progress: (%d/%d). Process file \"%s\"",
1906-
i + 1, n_backup_files_list, file->rel_path);
1904+
elog(progress ? INFO : LOG, "Progress: (%d/%d). Process file \"%s\"",
1905+
i + 1, n_backup_files_list, file->rel_path);
19071906

19081907
/* Handle zero sized files */
19091908
if (file->size == 0)
@@ -1973,11 +1972,11 @@ backup_files(void *arg)
19731972

19741973
if (file->write_size == BYTES_INVALID)
19751974
{
1976-
elog(VERBOSE, "Skipping the unchanged file: \"%s\"", from_fullpath);
1975+
elog(LOG, "Skipping the unchanged file: \"%s\"", from_fullpath);
19771976
continue;
19781977
}
19791978

1980-
elog(VERBOSE, "File \"%s\". Copied "INT64_FORMAT " bytes",
1979+
elog(LOG, "File \"%s\". Copied "INT64_FORMAT " bytes",
19811980
from_fullpath, file->write_size);
19821981
}
19831982

@@ -2095,26 +2094,26 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
20952094
elog(ERROR, "Out of memory");
20962095
len = strlen("/pg_compression");
20972096
cfs_tblspc_path[strlen(cfs_tblspc_path) - len] = 0;
2098-
elog(VERBOSE, "CFS DIRECTORY %s, pg_compression path: %s", cfs_tblspc_path, relative);
2097+
elog(LOG, "CFS DIRECTORY %s, pg_compression path: %s", cfs_tblspc_path, relative);
20992098

21002099
for (p = (int) i; p >= 0; p--)
21012100
{
21022101
prev_file = (pgFile *) parray_get(files, (size_t) p);
21032102

2104-
elog(VERBOSE, "Checking file in cfs tablespace %s", prev_file->rel_path);
2103+
elog(LOG, "Checking file in cfs tablespace %s", prev_file->rel_path);
21052104

21062105
if (strstr(prev_file->rel_path, cfs_tblspc_path) != NULL)
21072106
{
21082107
if (S_ISREG(prev_file->mode) && prev_file->is_datafile)
21092108
{
2110-
elog(VERBOSE, "Setting 'is_cfs' on file %s, name %s",
2109+
elog(LOG, "Setting 'is_cfs' on file %s, name %s",
21112110
prev_file->rel_path, prev_file->name);
21122111
prev_file->is_cfs = true;
21132112
}
21142113
}
21152114
else
21162115
{
2117-
elog(VERBOSE, "Breaking on %s", prev_file->rel_path);
2116+
elog(LOG, "Breaking on %s", prev_file->rel_path);
21182117
break;
21192118
}
21202119
}

src/catalog.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static pgBackup* get_closest_backup(timelineInfo *tlinfo);
2323
static pgBackup* get_oldest_backup(timelineInfo *tlinfo);
2424
static const char *backupModes[] = {"", "PAGE", "PTRACK", "DELTA", "FULL"};
2525
static pgBackup *readBackupControlFile(const char *path);
26-
static time_t create_backup_dir(pgBackup *backup, const char *backup_instance_path);
26+
static void create_backup_dir(pgBackup *backup, const char *backup_instance_path);
2727

2828
static bool backup_lock_exit_hook_registered = false;
2929
static parray *locks = NULL;
@@ -1426,10 +1426,12 @@ get_multi_timeline_parent(parray *backup_list, parray *tli_list,
14261426
* to fix it or let it be.
14271427
*/
14281428
void
1429-
pgBackupCreateDir(pgBackup *backup, const char *backup_instance_path)
1429+
pgBackupCreateDir(pgBackup *backup, InstanceState *instanceState, time_t start_time)
14301430
{
14311431
int i;
14321432
parray *subdirs = parray_new();
1433+
parray * backups;
1434+
pgBackup *target_backup;
14331435

14341436
parray_append(subdirs, pg_strdup(DATABASE_DIR));
14351437

@@ -1450,7 +1452,26 @@ pgBackupCreateDir(pgBackup *backup, const char *backup_instance_path)
14501452
free_dir_list(external_list);
14511453
}
14521454

1453-
backup->backup_id = create_backup_dir(backup, backup_instance_path);
1455+
/* Get list of all backups*/
1456+
backups = catalog_get_backup_list(instanceState, INVALID_BACKUP_ID);
1457+
if (parray_num(backups) > 0)
1458+
{
1459+
target_backup = (pgBackup *) parray_get(backups, 0);
1460+
if (start_time > target_backup->backup_id)
1461+
{
1462+
backup->backup_id = start_time;
1463+
create_backup_dir(backup, instanceState->instance_backup_subdir_path);
1464+
}
1465+
else
1466+
{
1467+
elog(ERROR, "Cannot create directory for older backup");
1468+
}
1469+
}
1470+
else
1471+
{
1472+
backup->backup_id = start_time;
1473+
create_backup_dir(backup, instanceState->instance_backup_subdir_path);
1474+
}
14541475

14551476
if (backup->backup_id == 0)
14561477
elog(ERROR, "Cannot create backup directory: %s", strerror(errno));
@@ -1477,7 +1498,7 @@ pgBackupCreateDir(pgBackup *backup, const char *backup_instance_path)
14771498
* Create root directory for backup,
14781499
* update pgBackup.root_dir if directory creation was a success
14791500
*/
1480-
time_t
1501+
void
14811502
create_backup_dir(pgBackup *backup, const char *backup_instance_path)
14821503
{
14831504
int attempts = 10;
@@ -1486,16 +1507,15 @@ create_backup_dir(pgBackup *backup, const char *backup_instance_path)
14861507
{
14871508
int rc;
14881509
char path[MAXPGPATH];
1489-
time_t backup_id = time(NULL);
14901510

1491-
join_path_components(path, backup_instance_path, base36enc(backup_id));
1511+
join_path_components(path, backup_instance_path, base36enc(backup->backup_id));
14921512

14931513
rc = fio_mkdir(FIO_BACKUP_HOST, path, DIR_PERMISSION, true);
14941514

14951515
if (rc == 0)
14961516
{
14971517
backup->root_dir = pgut_strdup(path);
1498-
return backup_id;
1518+
return;
14991519
}
15001520
else
15011521
{
@@ -1504,7 +1524,6 @@ create_backup_dir(pgBackup *backup, const char *backup_instance_path)
15041524
}
15051525
}
15061526

1507-
return 0;
15081527
}
15091528

15101529
/*

0 commit comments

Comments
 (0)