Skip to content

Commit 3b03593

Browse files
committed
Merge branch 'master' into stable
2 parents f1e3250 + 082612b commit 3b03593

File tree

17 files changed

+524
-279
lines changed

17 files changed

+524
-279
lines changed

src/backup.c

Lines changed: 249 additions & 191 deletions
Large diffs are not rendered by default.

src/catalog.c

Lines changed: 12 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

src/data.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
282282
*/
283283
bool
284284
backup_data_file(const char *from_root, const char *to_root,
285-
pgFile *file, XLogRecPtr prev_backup_start_lsn)
285+
pgFile *file, XLogRecPtr prev_backup_start_lsn,
286+
BackupMode backup_mode)
286287
{
287288
char to_path[MAXPGPATH];
288289
FILE *in;
@@ -292,6 +293,28 @@ backup_data_file(const char *from_root, const char *to_root,
292293
int n_blocks_skipped = 0;
293294
int n_blocks_read = 0;
294295

296+
if ((backup_mode == BACKUP_MODE_DIFF_PAGE ||
297+
backup_mode == BACKUP_MODE_DIFF_PTRACK) &&
298+
file->pagemap.bitmapsize == PageBitmapIsEmpty)
299+
{
300+
/*
301+
* There are no changed blocks since last backup. We want make
302+
* incremental backup, so we should exit.
303+
*/
304+
elog(VERBOSE, "Skipping the file because it didn`t changed: %s", file->path);
305+
return false;
306+
}
307+
308+
if ((backup_mode == BACKUP_MODE_DIFF_PAGE ||
309+
backup_mode == BACKUP_MODE_DIFF_PTRACK) &&
310+
file->pagemap.bitmapsize == PageBitmapIsAbsent)
311+
{
312+
/*
313+
* TODO COMPARE FILE CHECKSUMM to this file version from previous backup
314+
* if they are equal, skip this file
315+
*/
316+
}
317+
295318
/* reset size summary */
296319
file->read_size = 0;
297320
file->write_size = 0;
@@ -345,7 +368,8 @@ backup_data_file(const char *from_root, const char *to_root,
345368
* Read each page, verify checksum and write it to backup.
346369
* If page map is empty backup all pages of the relation.
347370
*/
348-
if (file->pagemap.bitmapsize == 0)
371+
if (file->pagemap.bitmapsize == PageBitmapIsEmpty
372+
|| file->pagemap.bitmapsize == PageBitmapIsAbsent)
349373
{
350374
for (blknum = 0; blknum < nblocks; blknum++)
351375
{

src/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pgFileInit(const char *path)
149149
file->is_datafile = false;
150150
file->linked = NULL;
151151
file->pagemap.bitmap = NULL;
152-
file->pagemap.bitmapsize = 0;
152+
file->pagemap.bitmapsize = PageBitmapIsAbsent;
153153
file->tblspcOid = 0;
154154
file->dbOid = 0;
155155
file->relOid = 0;

src/pg_probackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <sys/stat.h>
1818
#include <unistd.h>
1919

20-
const char *PROGRAM_VERSION = "2.0.10";
20+
const char *PROGRAM_VERSION = "2.0.11";
2121
const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
2222
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
2323

src/pg_probackup.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ typedef struct pgFile
104104
datapagemap_t pagemap; /* bitmap of pages updated since previous backup */
105105
} pgFile;
106106

107+
/* Special values of datapagemap_t bitmapsize */
108+
#define PageBitmapIsEmpty 0
109+
#define PageBitmapIsAbsent -1
110+
107111
/* Current state of backup */
108112
typedef enum BackupStatus
109113
{
@@ -211,6 +215,8 @@ typedef struct pgBackup
211215
uint32 wal_block_size;
212216
uint32 checksum_version;
213217

218+
char server_version[100];
219+
214220
bool stream; /* Was this backup taken in stream mode?
215221
* i.e. does it include all needed WAL files? */
216222
time_t parent_backup; /* Identifier of the previous backup.
@@ -413,7 +419,8 @@ extern int pgFileCompareSize(const void *f1, const void *f2);
413419

414420
/* in data.c */
415421
extern bool backup_data_file(const char *from_root, const char *to_root,
416-
pgFile *file, XLogRecPtr prev_backup_start_lsn);
422+
pgFile *file, XLogRecPtr prev_backup_start_lsn,
423+
BackupMode backup_mode);
417424
extern void restore_data_file(const char *from_root, const char *to_root,
418425
pgFile *file, pgBackup *backup);
419426
extern bool copy_file(const char *from_root, const char *to_root,

src/show.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ show_backup_list(FILE *out, parray *backup_list)
226226

227227
/* if you add new fields here, fix the header */
228228
/* show header */
229-
fputs("==================================================================================================================================\n", out);
230-
fputs(" Instance ID Recovery time Mode WAL Current/Parent TLI Time Data Start LSN Stop LSN Status\n", out);
231-
fputs("==================================================================================================================================\n", out);
229+
fputs("============================================================================================================================================\n", out);
230+
fputs(" Instance Version ID Recovery time Mode WAL Current/Parent TLI Time Data Start LSN Stop LSN Status \n", out);
231+
fputs("============================================================================================================================================\n", out);
232232

233233
for (i = 0; i < parray_num(backup_list); i++)
234234
{
@@ -257,8 +257,10 @@ show_backup_list(FILE *out, parray *backup_list)
257257
parent_tli = get_parent_tli(backup->tli);
258258
backup_id = base36enc(backup->start_time);
259259

260-
fprintf(out, " %-11s %-6s %-19s %-6s %-7s %3d / %-3d %5s %6s %2X/%-8X %2X/%-8X %-8s\n",
261-
instance_name, backup_id,
260+
fprintf(out, " %-11s %-8s %-6s %-22s %-6s %-7s %3d / %-3d %5s %6s %2X/%-8X %2X/%-8X %-8s\n",
261+
instance_name,
262+
(backup->server_version[0] ? backup->server_version : "----"),
263+
backup_id,
262264
timestamp,
263265
pgBackupGetBackupMode(backup),
264266
backup->stream ? "STREAM": "ARCHIVE",

src/util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ pgBackup_init(pgBackup *backup)
263263
backup->wal_block_size = XLOG_BLCKSZ;
264264
backup->stream = false;
265265
backup->parent_backup = 0;
266+
backup->server_version[0] = '\0';
266267
}

src/utils/pgut.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ const char *pgut_dbname = NULL;
3838
const char *host = NULL;
3939
const char *port = NULL;
4040
const char *username = NULL;
41-
char *password = NULL;
41+
static char *password = NULL;
4242
bool prompt_password = true;
4343

4444
/* Database connections */
4545
static PGcancel *volatile cancel_conn = NULL;
4646

4747
/* Interrupted by SIGINT (Ctrl+C) ? */
48-
bool interrupted = false;
49-
static bool in_cleanup = false;
48+
bool interrupted = false;
49+
bool in_cleanup = false;
5050

5151
static bool parse_pair(const char buffer[], char key[], char value[]);
5252

@@ -58,6 +58,7 @@ static void on_interrupt(void);
5858
static void on_cleanup(void);
5959
static void exit_or_abort(int exitcode);
6060
static const char *get_username(void);
61+
static pqsigfunc oldhandler = NULL;
6162

6263
/*
6364
* Unit conversion tables.
@@ -1079,13 +1080,15 @@ parse_pair(const char buffer[], char key[], char value[])
10791080
static void
10801081
prompt_for_password(const char *username)
10811082
{
1083+
pqsignal(SIGINT, oldhandler);
10821084
if (password)
10831085
{
10841086
free(password);
10851087
password = NULL;
10861088
}
10871089

10881090
#if PG_VERSION_NUM >= 100000
1091+
password = (char *) pgut_malloc(sizeof(char) * 100 + 1);
10891092
if (username == NULL)
10901093
simple_prompt("Password: ", password, 100, false);
10911094
else
@@ -1104,6 +1107,7 @@ prompt_for_password(const char *username)
11041107
password = simple_prompt(message, 100, false);
11051108
}
11061109
#endif
1110+
init_cancel_handler();
11071111
}
11081112

11091113
PGconn *
@@ -1138,6 +1142,9 @@ pgut_connect_extended(const char *pghost, const char *pgport,
11381142
if (interrupted)
11391143
elog(ERROR, "interrupted");
11401144

1145+
if (password == NULL || password[0] == '\0')
1146+
elog(ERROR, "no password supplied");
1147+
11411148
continue;
11421149
}
11431150
elog(ERROR, "could not connect to database %s: %s",
@@ -1819,7 +1826,7 @@ handle_sigint(SIGNAL_ARGS)
18191826
static void
18201827
init_cancel_handler(void)
18211828
{
1822-
pqsignal(SIGINT, handle_sigint);
1829+
oldhandler = pqsignal(SIGINT, handle_sigint);
18231830
}
18241831
#else /* WIN32 */
18251832

src/utils/pgut.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ extern const char *pgut_dbname;
101101
extern const char *host;
102102
extern const char *port;
103103
extern const char *username;
104-
extern char *password;
105104
extern bool prompt_password;
106105

107106
extern bool interrupted;
107+
extern bool in_cleanup;
108108

109109
extern int pgut_getopt(int argc, char **argv, pgut_option options[]);
110110
extern void pgut_readopt(const char *path, pgut_option options[], int elevel);

0 commit comments

Comments
 (0)