Skip to content

Commit 62e4e90

Browse files
committed
Add log file functions
1 parent 69b41b2 commit 62e4e90

File tree

14 files changed

+329
-186
lines changed

14 files changed

+329
-186
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ OBJS = backup.o \
88
fetch.o \
99
help.o \
1010
init.o \
11-
parray.o \
1211
pg_probackup.o \
1312
restore.o \
1413
show.o \
@@ -20,8 +19,9 @@ OBJS = backup.o \
2019
xlogreader.o \
2120
streamutil.o \
2221
receivelog.o \
23-
pgut/pgut.o \
24-
pgut/logger.o
22+
utils/parray.o \
23+
utils/pgut.o \
24+
utils/logger.o
2525

2626
EXTRA_CLEAN = datapagemap.c datapagemap.h xlogreader.c receivelog.c receivelog.h streamutil.c streamutil.h logging.h
2727

backup.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ do_backup_database(parray *backup_list)
276276
char dirpath[MAXPGPATH];
277277
char *dir_name = GetRelativePath(file->path, pgdata);
278278

279-
if (verbose)
280-
elog(LOG, "Create directory \"%s\"", dir_name);
279+
elog(LOG, "Create directory \"%s\"", dir_name);
281280

282281
join_path_components(dirpath, database_path, dir_name);
283282
dir_create_dir(dirpath, DIR_PERMISSION);
@@ -305,8 +304,7 @@ do_backup_database(parray *backup_list)
305304
/* Run threads */
306305
for (i = 0; i < num_threads; i++)
307306
{
308-
if (verbose)
309-
elog(WARNING, "Start thread num:%li", parray_num(backup_threads_args[i]->backup_files_list));
307+
elog(LOG, "Start thread num:%li", parray_num(backup_threads_args[i]->backup_files_list));
310308
pthread_create(&backup_threads[i], NULL, (void *(*)(void *)) backup_files, backup_threads_args[i]);
311309
}
312310

@@ -1157,9 +1155,8 @@ backup_files(void *arg)
11571155
if (prev_file && false)
11581156
{
11591157
file->write_size = BYTES_INVALID;
1160-
if (verbose)
1161-
elog(LOG, "File \"%s\" has not changed since previous backup",
1162-
file->path);
1158+
elog(LOG, "File \"%s\" has not changed since previous backup",
1159+
file->path);
11631160
continue;
11641161
}
11651162
}
@@ -1554,10 +1551,9 @@ stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
15541551
static XLogRecPtr prevpos = InvalidXLogRecPtr;
15551552

15561553
/* we assume that we get called once at the end of each segment */
1557-
if (verbose && segment_finished)
1558-
fprintf(stderr, _("%s: finished segment at %X/%X (timeline %u)\n"),
1559-
PROGRAM_NAME, (uint32) (xlogpos >> 32), (uint32) xlogpos,
1560-
timeline);
1554+
if (segment_finished)
1555+
elog(LOG, _("finished segment at %X/%X (timeline %u)\n"),
1556+
(uint32) (xlogpos >> 32), (uint32) xlogpos, timeline);
15611557

15621558
/*
15631559
* Note that we report the previous, not current, position here. After a
@@ -1568,9 +1564,8 @@ stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
15681564
* timeline, but it's close enough for reporting purposes.
15691565
*/
15701566
if (prevtimeline != 0 && prevtimeline != timeline)
1571-
fprintf(stderr, _("%s: switched to timeline %u at %X/%X\n"),
1572-
PROGRAM_NAME, timeline,
1573-
(uint32) (prevpos >> 32), (uint32) prevpos);
1567+
elog(LOG, _("switched to timeline %u at %X/%X\n"),
1568+
timeline, (uint32) (prevpos >> 32), (uint32) prevpos);
15741569

15751570
if (stop_backup_lsn != InvalidXLogRecPtr && xlogpos > stop_backup_lsn)
15761571
return true;
@@ -1637,11 +1632,8 @@ StreamLog(void *arg)
16371632
/*
16381633
* Start the replication
16391634
*/
1640-
if (verbose)
1641-
fprintf(stderr,
1642-
_("%s: starting log streaming at %X/%X (timeline %u)\n"),
1643-
PROGRAM_NAME, (uint32) (startpos >> 32), (uint32) startpos,
1644-
starttli);
1635+
elog(LOG, _("starting log streaming at %X/%X (timeline %u)\n"),
1636+
(uint32) (startpos >> 32), (uint32) startpos, starttli);
16451637

16461638
#if PG_VERSION_NUM >= 90600
16471639
{

data.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
119119
/* Try to read and verify this page again several times. */
120120
if (try_checksum)
121121
{
122-
if (verbose)
123-
elog(WARNING, "File: %s blknum %u have wrong page header, try again",
124-
file->path, blknum);
122+
elog(WARNING, "File: %s blknum %u have wrong page header, try again",
123+
file->path, blknum);
125124
usleep(100);
126125
continue;
127126
}
@@ -150,9 +149,8 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
150149
{
151150
if (try_checksum)
152151
{
153-
if (verbose)
154-
elog(WARNING, "File: %s blknum %u have wrong checksum, try again",
155-
file->path, blknum);
152+
elog(WARNING, "File: %s blknum %u have wrong checksum, try again",
153+
file->path, blknum);
156154
usleep(100);
157155
}
158156
else

delete.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ delete_walfiles(XLogRecPtr oldest_lsn, TimeLineID oldest_tli, bool delete_all)
356356
wal_file, strerror(errno));
357357
break;
358358
}
359-
if (verbose)
360-
elog(LOG, "removed WAL segment \"%s\"", wal_file);
359+
elog(LOG, "removed WAL segment \"%s\"", wal_file);
361360

362361
if (max_wal_file[0] == '\0' ||
363362
strcmp(max_wal_file + 8, arcde->d_name + 8) < 0)
@@ -370,9 +369,9 @@ delete_walfiles(XLogRecPtr oldest_lsn, TimeLineID oldest_tli, bool delete_all)
370369
}
371370
}
372371

373-
if (!verbose && min_wal_file[0] != '\0')
372+
if (min_wal_file[0] != '\0')
374373
elog(INFO, "removed min WAL segment \"%s\"", min_wal_file);
375-
if (!verbose && max_wal_file[0] != '\0')
374+
if (max_wal_file[0] != '\0')
376375
elog(INFO, "removed max WAL segment \"%s\"", max_wal_file);
377376

378377
if (errno)

pg_probackup.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ static pgut_option options[] =
9898
{ 's', 'h', "pghost" , &host, SOURCE_CMDLINE },
9999
{ 's', 'p', "pgport" , &port, SOURCE_CMDLINE },
100100
{ 's', 'U', "pguser" , &username, SOURCE_CMDLINE },
101-
{ 'b', 'q', "quiet" , &quiet, SOURCE_CMDLINE },
102-
{ 'b', 'v', "verbose" , &verbose, SOURCE_CMDLINE },
103101
{ 'B', 'w', "no-password" , &prompt_password, SOURCE_CMDLINE },
104102
{ 0 }
105103
};
@@ -197,14 +195,21 @@ main(int argc, char *argv[])
197195
pgut_getopt_env(options);
198196
}
199197

198+
/*
199+
* We read backup path from command line or from configuration file.
200+
* Do final check.
201+
*/
202+
if (!is_absolute_path(backup_path))
203+
elog(ERROR, "-B, --backup-path must be an absolute path");
204+
200205
if (backup_id_string_param != NULL)
201206
{
202207
current.backup_id = base36dec(backup_id_string_param);
203208
if (current.backup_id == 0)
204209
elog(ERROR, "Invalid backup-id");
205210
}
206211

207-
/* setup stream options */
212+
/* Setup stream options. They are used in streamutil.c. */
208213
if (pgut_dbname != NULL)
209214
dbname = pstrdup(pgut_dbname);
210215
if (host != NULL)
@@ -214,9 +219,10 @@ main(int argc, char *argv[])
214219
if (username != NULL)
215220
dbuser = pstrdup(username);
216221

217-
/* path must be absolute */
218-
if (!is_absolute_path(backup_path))
219-
elog(ERROR, "-B, --backup-path must be an absolute path");
222+
/*
223+
* We read pgdata path from command line or from configuration file.
224+
* Do final check.
225+
*/
220226
if (pgdata != NULL && !is_absolute_path(pgdata))
221227
elog(ERROR, "-D, --pgdata must be an absolute path");
222228

pg_probackup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
#include "storage/checksum.h"
2929
#include "utils/pg_crc.h"
3030

31-
#include "pgut/pgut.h"
31+
#include "utils/parray.h"
32+
#include "utils/pgut.h"
3233

3334
#include "datapagemap.h"
34-
#include "parray.h"
3535

3636

3737
/* Directory/File names */

pgut/logger.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

restore.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ restore_backup(pgBackup *backup)
332332
arg->files = files;
333333
arg->backup = backup;
334334

335-
if (verbose)
336-
elog(LOG, "Start thread for num:%li", parray_num(files));
335+
elog(LOG, "Start thread for num:%li", parray_num(files));
337336

338337
restore_threads_args[i] = arg;
339338
pthread_create(&restore_threads[i], NULL, (void *(*)(void *)) restore_files, arg);
@@ -350,7 +349,7 @@ restore_backup(pgBackup *backup)
350349
parray_walk(files, pgFileFree);
351350
parray_free(files);
352351

353-
if (verbose)
352+
if (log_level <= LOG)
354353
{
355354
char *backup_id;
356355

@@ -395,7 +394,7 @@ remove_deleted_files(pgBackup *backup)
395394
if (parray_bsearch(files, file, pgFileComparePathDesc) == NULL)
396395
{
397396
pgFileDelete(file);
398-
if (verbose)
397+
if (log_level <= LOG)
399398
elog(LOG, "deleted %s", GetRelativePath(file->path, pgdata));
400399
}
401400
}

0 commit comments

Comments
 (0)