Skip to content

Commit 16c0508

Browse files
committed
Merge branch 'master' into REL_2_6
2 parents c44550d + a58c183 commit 16c0508

30 files changed

+1184
-212
lines changed

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
@@ -116,7 +116,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
116116
char pretty_time[20];
117117
char pretty_bytes[20];
118118

119-
elog(LOG, "Database backup start");
119+
elog(INFO, "Database backup start");
120120
if(current.external_dir_str)
121121
{
122122
external_dirs = make_external_directory_list(current.external_dir_str,
@@ -337,11 +337,11 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
337337
/* Extract information about files in backup_list parsing their names:*/
338338
parse_filelist_filenames(backup_files_list, instance_config.pgdata);
339339

340-
elog(LOG, "Current Start LSN: %X/%X, TLI: %X",
340+
elog(INFO, "Current Start LSN: %X/%X, TLI: %X",
341341
(uint32) (current.start_lsn >> 32), (uint32) (current.start_lsn),
342342
current.tli);
343343
if (current.backup_mode != BACKUP_MODE_FULL)
344-
elog(LOG, "Parent Start LSN: %X/%X, TLI: %X",
344+
elog(INFO, "Parent Start LSN: %X/%X, TLI: %X",
345345
(uint32) (prev_backup->start_lsn >> 32), (uint32) (prev_backup->start_lsn),
346346
prev_backup->tli);
347347

@@ -413,7 +413,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
413413
else
414414
join_path_components(dirpath, current.database_dir, file->rel_path);
415415

416-
elog(VERBOSE, "Create directory '%s'", dirpath);
416+
elog(LOG, "Create directory '%s'", dirpath);
417417
fio_mkdir(FIO_BACKUP_HOST, dirpath, DIR_PERMISSION, false);
418418
}
419419

@@ -674,7 +674,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
674674
nodeInfo->checksum_version = current.checksum_version;
675675

676676
if (current.checksum_version)
677-
elog(LOG, "This PostgreSQL instance was initialized with data block checksums. "
677+
elog(INFO, "This PostgreSQL instance was initialized with data block checksums. "
678678
"Data block corruption will be detected");
679679
else
680680
elog(WARNING, "This PostgreSQL instance was initialized without data block checksums. "
@@ -696,7 +696,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
696696
*/
697697
int
698698
do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
699-
bool no_validate, bool no_sync, bool backup_logs)
699+
bool no_validate, bool no_sync, bool backup_logs, time_t start_time)
700700
{
701701
PGconn *backup_conn = NULL;
702702
PGNodeInfo nodeInfo;
@@ -711,7 +711,7 @@ do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
711711
current.external_dir_str = instance_config.external_dir_str;
712712

713713
/* Create backup directory and BACKUP_CONTROL_FILE */
714-
pgBackupCreateDir(&current, instanceState->instance_backup_subdir_path);
714+
pgBackupCreateDir(&current, instanceState, start_time);
715715

716716
if (!instance_config.pgdata)
717717
elog(ERROR, "required parameter not specified: PGDATA "
@@ -1514,7 +1514,7 @@ wait_wal_and_calculate_stop_lsn(const char *xlog_path, XLogRecPtr stop_lsn, pgBa
15141514
stop_lsn_exists = true;
15151515
}
15161516

1517-
elog(LOG, "stop_lsn: %X/%X",
1517+
elog(INFO, "stop_lsn: %X/%X",
15181518
(uint32) (stop_lsn >> 32), (uint32) (stop_lsn));
15191519

15201520
/*
@@ -1903,15 +1903,15 @@ pg_stop_backup(InstanceState *instanceState, pgBackup *backup, PGconn *pg_startb
19031903

19041904
backup->recovery_xid = stop_backup_result.snapshot_xid;
19051905

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

19081908
/* iterate over WAL from stop_backup lsn to start_backup lsn */
19091909
if (!read_recovery_info(xlog_path, backup->tli,
19101910
instance_config.xlog_seg_size,
19111911
backup->start_lsn, backup->stop_lsn,
19121912
&backup->recovery_time))
19131913
{
1914-
elog(LOG, "Failed to find Recovery Time in WAL, forced to trust current_timestamp");
1914+
elog(INFO, "Failed to find Recovery Time in WAL, forced to trust current_timestamp");
19151915
backup->recovery_time = stop_backup_result.invocation_time;
19161916
}
19171917

@@ -1993,9 +1993,8 @@ backup_files(void *arg)
19931993
if (interrupted || thread_interrupted)
19941994
elog(ERROR, "interrupted during backup");
19951995

1996-
if (progress)
1997-
elog(INFO, "Progress: (%d/%d). Process file \"%s\"",
1998-
i + 1, n_backup_files_list, file->rel_path);
1996+
elog(progress ? INFO : LOG, "Progress: (%d/%d). Process file \"%s\"",
1997+
i + 1, n_backup_files_list, file->rel_path);
19991998

20001999
/* Handle zero sized files */
20012000
if (file->size == 0)
@@ -2065,11 +2064,11 @@ backup_files(void *arg)
20652064

20662065
if (file->write_size == BYTES_INVALID)
20672066
{
2068-
elog(VERBOSE, "Skipping the unchanged file: \"%s\"", from_fullpath);
2067+
elog(LOG, "Skipping the unchanged file: \"%s\"", from_fullpath);
20692068
continue;
20702069
}
20712070

2072-
elog(VERBOSE, "File \"%s\". Copied "INT64_FORMAT " bytes",
2071+
elog(LOG, "File \"%s\". Copied "INT64_FORMAT " bytes",
20732072
from_fullpath, file->write_size);
20742073
}
20752074

@@ -2187,26 +2186,26 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
21872186
elog(ERROR, "Out of memory");
21882187
len = strlen("/pg_compression");
21892188
cfs_tblspc_path[strlen(cfs_tblspc_path) - len] = 0;
2190-
elog(VERBOSE, "CFS DIRECTORY %s, pg_compression path: %s", cfs_tblspc_path, relative);
2189+
elog(LOG, "CFS DIRECTORY %s, pg_compression path: %s", cfs_tblspc_path, relative);
21912190

21922191
for (p = (int) i; p >= 0; p--)
21932192
{
21942193
prev_file = (pgFile *) parray_get(files, (size_t) p);
21952194

2196-
elog(VERBOSE, "Checking file in cfs tablespace %s", prev_file->rel_path);
2195+
elog(LOG, "Checking file in cfs tablespace %s", prev_file->rel_path);
21972196

21982197
if (strstr(prev_file->rel_path, cfs_tblspc_path) != NULL)
21992198
{
22002199
if (S_ISREG(prev_file->mode) && prev_file->is_datafile)
22012200
{
2202-
elog(VERBOSE, "Setting 'is_cfs' on file %s, name %s",
2201+
elog(LOG, "Setting 'is_cfs' on file %s, name %s",
22032202
prev_file->rel_path, prev_file->name);
22042203
prev_file->is_cfs = true;
22052204
}
22062205
}
22072206
else
22082207
{
2209-
elog(VERBOSE, "Breaking on %s", prev_file->rel_path);
2208+
elog(LOG, "Breaking on %s", prev_file->rel_path);
22102209
break;
22112210
}
22122211
}

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)