Skip to content

Commit c36a0ff

Browse files
s.logvinenkos.logvinenko
authored andcommitted
Merge branch 'master' of https://git.postgrespro.ru/pgpro-dev/pg_probackup into testgres1
Conflicts: tests/auth_test.py tests/helpers/ptrack_helpers.py tests/ptrack.py
2 parents 3e290f0 + edc1b31 commit c36a0ff

27 files changed

+1273
-538
lines changed

src/backup.c

Lines changed: 275 additions & 174 deletions
Large diffs are not rendered by default.

src/catalog.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
394394
fprintf(out, "block-size = %u\n", backup->block_size);
395395
fprintf(out, "xlog-block-size = %u\n", backup->wal_block_size);
396396
fprintf(out, "checksum-version = %u\n", backup->checksum_version);
397+
if (backup->server_version[0] != '\0')
398+
fprintf(out, "server-version = %s\n", backup->server_version);
397399

398400
fprintf(out, "\n#Result backup info\n");
399401
fprintf(out, "timelineid = %d\n", backup->tli);
@@ -475,6 +477,7 @@ readBackupControlFile(const char *path)
475477
char *status = NULL;
476478
char *parent_backup = NULL;
477479
char *compress_alg = NULL;
480+
char *server_version = NULL;
478481
int *compress_level;
479482
bool *from_replica;
480483

@@ -492,7 +495,8 @@ readBackupControlFile(const char *path)
492495
{'I', 0, "wal-bytes", &backup->wal_bytes, SOURCE_FILE_STRICT},
493496
{'u', 0, "block-size", &backup->block_size, SOURCE_FILE_STRICT},
494497
{'u', 0, "xlog-block-size", &backup->wal_block_size, SOURCE_FILE_STRICT},
495-
{'u', 0, "checksum_version", &backup->checksum_version, SOURCE_FILE_STRICT},
498+
{'u', 0, "checksum-version", &backup->checksum_version, SOURCE_FILE_STRICT},
499+
{'s', 0, "server-version", &server_version, SOURCE_FILE_STRICT},
496500
{'b', 0, "stream", &backup->stream, SOURCE_FILE_STRICT},
497501
{'s', 0, "status", &status, SOURCE_FILE_STRICT},
498502
{'s', 0, "parent-backup-id", &parent_backup, SOURCE_FILE_STRICT},
@@ -565,6 +569,13 @@ readBackupControlFile(const char *path)
565569
free(parent_backup);
566570
}
567571

572+
if (server_version)
573+
{
574+
StrNCpy(backup->server_version, server_version,
575+
sizeof(backup->server_version));
576+
pfree(server_version);
577+
}
578+
568579
return backup;
569580
}
570581

@@ -591,6 +602,24 @@ parse_backup_mode(const char *value)
591602
return BACKUP_MODE_INVALID;
592603
}
593604

605+
const char *
606+
deparse_backup_mode(BackupMode mode)
607+
{
608+
switch (mode)
609+
{
610+
case BACKUP_MODE_FULL:
611+
return "full";
612+
case BACKUP_MODE_DIFF_PAGE:
613+
return "page";
614+
case BACKUP_MODE_DIFF_PTRACK:
615+
return "ptrack";
616+
case BACKUP_MODE_INVALID:
617+
return "invalid";
618+
}
619+
620+
return NULL;
621+
}
622+
594623
/* free pgBackup object */
595624
void
596625
pgBackupFree(void *backup)

src/configure.c

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
#include "pg_probackup.h"
1111

12-
static void opt_log_level(pgut_option *opt, const char *arg);
12+
static void opt_log_level_console(pgut_option *opt, const char *arg);
13+
static void opt_log_level_file(pgut_option *opt, const char *arg);
1314
static void opt_compress_alg(pgut_option *opt, const char *arg);
1415

1516
static pgBackupConfig *cur_config = NULL;
@@ -41,10 +42,10 @@ do_configure(bool show_only)
4142
if (replica_timeout != 300) /* 300 is default value */
4243
config->replica_timeout = replica_timeout;
4344

44-
if (log_to_file != LOGGER_NONE)
45-
config->log_to_file = LOG_TO_FILE;
46-
if (log_level != LOGGER_NONE)
47-
config->log_level = LOG_LEVEL;
45+
if (log_level_console != LOG_NONE)
46+
config->log_level_console = LOG_LEVEL_CONSOLE;
47+
if (log_level_file != LOG_NONE)
48+
config->log_level_file = LOG_LEVEL_FILE;
4849
if (log_filename)
4950
config->log_filename = log_filename;
5051
if (error_log_filename)
@@ -90,8 +91,8 @@ pgBackupConfigInit(pgBackupConfig *config)
9091
config->master_user = NULL;
9192
config->replica_timeout = INT_MIN; /* INT_MIN means "undefined" */
9293

93-
config->log_to_file = INT_MIN; /* INT_MIN means "undefined" */
94-
config->log_level = INT_MIN; /* INT_MIN means "undefined" */
94+
config->log_level_console = INT_MIN; /* INT_MIN means "undefined" */
95+
config->log_level_file = INT_MIN; /* INT_MIN means "undefined" */
9596
config->log_filename = NULL;
9697
config->error_log_filename = NULL;
9798
config->log_directory = NULL;
@@ -108,6 +109,9 @@ pgBackupConfigInit(pgBackupConfig *config)
108109
void
109110
writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
110111
{
112+
uint64 res;
113+
const char *unit;
114+
111115
fprintf(out, "#Backup instance info\n");
112116
fprintf(out, "PGDATA = %s\n", config->pgdata);
113117
fprintf(out, "system-identifier = %li\n", config->system_identifier);
@@ -131,24 +135,41 @@ writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
131135
fprintf(out, "master-db = %s\n", config->master_db);
132136
if (config->master_user)
133137
fprintf(out, "master-user = %s\n", config->master_user);
138+
134139
if (config->replica_timeout != INT_MIN)
135-
fprintf(out, "replica_timeout = %d\n", config->replica_timeout);
140+
{
141+
convert_from_base_unit_u(config->replica_timeout, OPTION_UNIT_S,
142+
&res, &unit);
143+
fprintf(out, "replica-timeout = " UINT64_FORMAT "%s\n", res, unit);
144+
}
136145

137146
fprintf(out, "#Logging parameters:\n");
138-
if (config->log_to_file != INT_MIN)
139-
fprintf(out, "log = %d\n", config->log_to_file);
140-
if (config->log_level != INT_MIN)
141-
fprintf(out, "log-level = %s\n", deparse_log_level(config->log_level));
147+
if (config->log_level_console != INT_MIN)
148+
fprintf(out, "log-level-console = %s\n", deparse_log_level(config->log_level_console));
149+
if (config->log_level_file != INT_MIN)
150+
fprintf(out, "log-level-file = %s\n", deparse_log_level(config->log_level_file));
142151
if (config->log_filename)
143152
fprintf(out, "log-filename = %s\n", config->log_filename);
144153
if (config->error_log_filename)
145154
fprintf(out, "error-log-filename = %s\n", config->error_log_filename);
146155
if (config->log_directory)
147156
fprintf(out, "log-directory = %s\n", config->log_directory);
157+
158+
/*
159+
* Convert values from base unit
160+
*/
148161
if (config->log_rotation_size)
149-
fprintf(out, "log-rotation-size = %d\n", config->log_rotation_size);
162+
{
163+
convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB,
164+
&res, &unit);
165+
fprintf(out, "log-rotation-size = " UINT64_FORMAT "%s\n", res, unit);
166+
}
150167
if (config->log_rotation_age)
151-
fprintf(out, "log-rotation-age = %d\n", config->log_rotation_age);
168+
{
169+
convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S,
170+
&res, &unit);
171+
fprintf(out, "log-rotation-age = " UINT64_FORMAT "%s\n", res, unit);
172+
}
152173

153174
fprintf(out, "#Retention parameters:\n");
154175
if (config->retention_redundancy)
@@ -198,13 +219,13 @@ readBackupCatalogConfigFile(void)
198219
{ 'f', 0, "compress-algorithm", opt_compress_alg, SOURCE_CMDLINE },
199220
{ 'u', 0, "compress-level", &(config->compress_level), SOURCE_CMDLINE },
200221
/* logging options */
201-
{ 'b', 0, "log", &(config->log_to_file), SOURCE_CMDLINE },
202-
{ 'f', 0, "log-level", opt_log_level, SOURCE_CMDLINE },
222+
{ 'f', 0, "log-level-console", opt_log_level_console, SOURCE_CMDLINE },
223+
{ 'f', 0, "log-level-file", opt_log_level_file, SOURCE_CMDLINE },
203224
{ 's', 0, "log-filename", &(config->log_filename), SOURCE_CMDLINE },
204225
{ 's', 0, "error-log-filename", &(config->error_log_filename), SOURCE_CMDLINE },
205226
{ 's', 0, "log-directory", &(config->log_directory), SOURCE_CMDLINE },
206-
{ 'u', 0, "log-rotation-size", &(config->log_rotation_size), SOURCE_CMDLINE },
207-
{ 'u', 0, "log-rotation-age", &(config->log_rotation_age), SOURCE_CMDLINE },
227+
{ 'u', 0, "log-rotation-size", &(config->log_rotation_size), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_KB },
228+
{ 'u', 0, "log-rotation-age", &(config->log_rotation_age), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_S },
208229
/* connection options */
209230
{ 's', 0, "pgdata", &(config->pgdata), SOURCE_FILE_STRICT },
210231
{ 's', 0, "pgdatabase", &(config->pgdatabase), SOURCE_FILE_STRICT },
@@ -216,7 +237,7 @@ readBackupCatalogConfigFile(void)
216237
{ 's', 0, "master-port", &(config->master_port), SOURCE_FILE_STRICT },
217238
{ 's', 0, "master-db", &(config->master_db), SOURCE_FILE_STRICT },
218239
{ 's', 0, "master-user", &(config->master_user), SOURCE_FILE_STRICT },
219-
{ 'u', 0, "replica-timeout", &(config->replica_timeout), SOURCE_CMDLINE },
240+
{ 'u', 0, "replica-timeout", &(config->replica_timeout), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_S },
220241
/* other options */
221242
{ 'U', 0, "system-identifier", &(config->system_identifier), SOURCE_FILE_STRICT },
222243
{0}
@@ -234,9 +255,15 @@ readBackupCatalogConfigFile(void)
234255
}
235256

236257
static void
237-
opt_log_level(pgut_option *opt, const char *arg)
258+
opt_log_level_console(pgut_option *opt, const char *arg)
259+
{
260+
cur_config->log_level_console = parse_log_level(arg);
261+
}
262+
263+
static void
264+
opt_log_level_file(pgut_option *opt, const char *arg)
238265
{
239-
cur_config->log_level = parse_log_level(arg);
266+
cur_config->log_level_file = parse_log_level(arg);
240267
}
241268

242269
static void

src/data.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
140140
/*
141141
* Read the page and verify its header and checksum.
142142
* Under high write load it's possible that we've read partly
143-
* flushed page, so try several times befor throwing an error.
143+
* flushed page, so try several times before throwing an error.
144144
*/
145145
while(try_checksum--)
146146
{
@@ -152,6 +152,20 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
152152

153153
if (read_len != BLCKSZ)
154154
{
155+
if (read_len == 0)
156+
{
157+
elog(LOG, "File %s, block %u, file was truncated",
158+
file->path, blknum);
159+
return;
160+
}
161+
else if (try_checksum)
162+
{
163+
elog(LOG, "File: %s, block %u, expected block size %lu, but read %d, try again",
164+
file->path, blknum, read_len, BLCKSZ);
165+
usleep(100);
166+
continue;
167+
}
168+
155169
elog(ERROR, "File: %s, invalid block size of block %u : %lu",
156170
file->path, blknum, read_len);
157171
}
@@ -295,15 +309,26 @@ backup_data_file(const char *from_root, const char *to_root,
295309

296310
if ((backup_mode == BACKUP_MODE_DIFF_PAGE ||
297311
backup_mode == BACKUP_MODE_DIFF_PTRACK) &&
298-
file->pagemap.bitmapsize == 0)
312+
file->pagemap.bitmapsize == PageBitmapIsEmpty)
299313
{
300314
/*
301315
* There are no changed blocks since last backup. We want make
302316
* incremental backup, so we should exit.
303317
*/
318+
elog(VERBOSE, "Skipping the file because it didn`t changed: %s", file->path);
304319
return false;
305320
}
306321

322+
if ((backup_mode == BACKUP_MODE_DIFF_PAGE ||
323+
backup_mode == BACKUP_MODE_DIFF_PTRACK) &&
324+
file->pagemap.bitmapsize == PageBitmapIsAbsent)
325+
{
326+
/*
327+
* TODO COMPARE FILE CHECKSUMM to this file version from previous backup
328+
* if they are equal, skip this file
329+
*/
330+
}
331+
307332
/* reset size summary */
308333
file->read_size = 0;
309334
file->write_size = 0;
@@ -357,7 +382,8 @@ backup_data_file(const char *from_root, const char *to_root,
357382
* Read each page, verify checksum and write it to backup.
358383
* If page map is empty backup all pages of the relation.
359384
*/
360-
if (file->pagemap.bitmapsize == 0)
385+
if (file->pagemap.bitmapsize == PageBitmapIsEmpty
386+
|| file->pagemap.bitmapsize == PageBitmapIsAbsent)
361387
{
362388
for (blknum = 0; blknum < nblocks; blknum++)
363389
{
@@ -482,7 +508,7 @@ restore_data_file(const char *from_root,
482508
if (header.block < blknum)
483509
elog(ERROR, "backup is broken at block %u", blknum);
484510

485-
elog(VERBOSE, "file %s, header compressed size %d", file->path, header.compressed_size);
511+
//elog(VERBOSE, "file %s, header compressed size %d", file->path, header.compressed_size);
486512
Assert(header.compressed_size <= BLCKSZ);
487513

488514
read_len = fread(compressed_page.data, 1,

src/dir.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static char *pgdata_exclude_files[] =
7575
"recovery.conf",
7676
"postmaster.pid",
7777
"postmaster.opts",
78+
"backup_label",
79+
"tablespace_map",
7880
NULL
7981
};
8082

@@ -149,7 +151,7 @@ pgFileInit(const char *path)
149151
file->is_datafile = false;
150152
file->linked = NULL;
151153
file->pagemap.bitmap = NULL;
152-
file->pagemap.bitmapsize = 0;
154+
file->pagemap.bitmapsize = (current.backup_mode == BACKUP_MODE_DIFF_PAGE) ? PageBitmapIsEmpty : PageBitmapIsAbsent;
153155
file->tblspcOid = 0;
154156
file->dbOid = 0;
155157
file->relOid = 0;
@@ -793,7 +795,7 @@ get_control_value(const char *str, const char *name,
793795
name, str, DATABASE_FILE_LIST);
794796

795797
*buf_uint64_ptr = '\0';
796-
if (!parse_uint64(buf_uint64, value_uint64))
798+
if (!parse_uint64(buf_uint64, value_uint64, 0))
797799
goto bad_format;
798800
}
799801

src/help.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ help_pg_probackup(void)
6666
printf(_("\n %s init -B backup-path [-l]\n"), PROGRAM_NAME);
6767

6868
printf(_("\n %s set-config -B backup-dir --instance=instance_name\n"), PROGRAM_NAME);
69-
printf(_(" [--log-level=log-level]\n"));
69+
printf(_(" [--log-level-console=log-level-console]\n"));
70+
printf(_(" [--log-level-file=log-level-file]\n"));
7071
printf(_(" [--log-filename=log-filename]\n"));
7172
printf(_(" [--error-log-filename=error-log-filename]\n"));
7273
printf(_(" [--log-directory=log-directory]\n"));
@@ -130,9 +131,8 @@ help_pg_probackup(void)
130131
static void
131132
help_init(void)
132133
{
133-
printf(_("%s init -B backup-path -D pgdata-dir [-l]\n\n"), PROGRAM_NAME);
134+
printf(_("%s init -B backup-path [-l]\n\n"), PROGRAM_NAME);
134135
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
135-
printf(_(" -l, --log store messages in a log file\n"));
136136
}
137137

138138
static void
@@ -153,7 +153,6 @@ help_backup(void)
153153
printf(_(" -b, --backup-mode=backup-mode backup mode=FULL|PAGE|PTRACK\n"));
154154
printf(_(" --instance=instance_name name of the instance\n"));
155155
printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n"));
156-
printf(_(" -l, --log store messages in a log file\n"));
157156
printf(_(" --stream stream the transaction log and include it in the backup\n"));
158157
printf(_(" --archive-timeout wait timeout for WAL segment archiving\n"));
159158
printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
@@ -195,7 +194,6 @@ help_restore(void)
195194
printf(_(" --instance=instance_name name of the instance\n"));
196195

197196
printf(_(" -D, --pgdata=pgdata-dir location of the database storage area\n"));
198-
printf(_(" -l, --log store messages in a log file\n"));
199197
printf(_(" -i, --backup-id=backup-id backup to restore\n"));
200198

201199
printf(_(" --progress show progress\n"));
@@ -219,7 +217,6 @@ help_validate(void)
219217
printf(_(" --instance=instance_name name of the instance\n"));
220218
printf(_(" -i, --backup-id=backup-id backup to validate\n"));
221219

222-
printf(_(" -l, --log store messages in a log file\n"));
223220
printf(_(" --progress show progress\n"));
224221
printf(_(" --time=time time stamp up to which recovery will proceed\n"));
225222
printf(_(" --xid=xid transaction ID up to which recovery will proceed\n"));
@@ -250,14 +247,14 @@ help_delete(void)
250247
printf(_(" -i, --backup-id=backup-id backup to delete\n"));
251248
printf(_(" --expired delete backups expired according to current\n"));
252249
printf(_(" retention policy\n"));
253-
printf(_(" -l, --log store messages in a log file\n"));
254250
}
255251

256252
static void
257253
help_set_config(void)
258254
{
259255
printf(_("%s set-config -B backup-dir --instance=instance_name\n"), PROGRAM_NAME);
260-
printf(_(" [--log-level=log-level]\n"));
256+
printf(_(" [--log-level-console=log-level-console]\n"));
257+
printf(_(" [--log-level-file=log-level-file]\n"));
261258
printf(_(" [--log-filename=log-filename]\n"));
262259
printf(_(" [--error-log-filename=error-log-filename]\n"));
263260
printf(_(" [--log-directory=log-directory]\n"));
@@ -276,7 +273,10 @@ help_set_config(void)
276273
printf(_(" --instance=instance_name name of the instance\n"));
277274

278275
printf(_("\n Logging options:\n"));
279-
printf(_(" --log-level=log-level controls which message levels are sent to the log\n"));
276+
printf(_(" --log-level-console=log-level-console\n"
277+
" controls which message levels are sent to the stderr\n"));
278+
printf(_(" --log-level-file=log-level-file\n"
279+
" controls which message levels are sent to a log file\n"));
280280
printf(_(" --log-filename=log-filename file names of the created log files which is treated as as strftime pattern\n"));
281281
printf(_(" --error-log-filename=error-log-filename\n"));
282282
printf(_(" file names of the created log files for error messages\n"));

0 commit comments

Comments
 (0)