1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-03-22 21:51:29 +02:00

Merge branch 'master' into pgpro_428_v1

This commit is contained in:
Anastasia 2018-08-02 15:39:45 +03:00
commit 27497d54c5
10 changed files with 159 additions and 129 deletions

View File

@ -8,6 +8,7 @@
*/ */
#include "pg_probackup.h" #include "pg_probackup.h"
#include "utils/logger.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
@ -57,13 +58,17 @@ do_configure(bool show_only)
config->master_db = master_db; config->master_db = master_db;
if (master_user) if (master_user)
config->master_user = master_user; config->master_user = master_user;
if (replica_timeout != 300) /* 300 is default value */
if (replica_timeout)
config->replica_timeout = replica_timeout; config->replica_timeout = replica_timeout;
if (log_level_console != LOG_NONE) if (archive_timeout)
config->log_level_console = LOG_LEVEL_CONSOLE; config->archive_timeout = archive_timeout;
if (log_level_file != LOG_NONE)
config->log_level_file = LOG_LEVEL_FILE; if (log_level_console)
config->log_level_console = log_level_console;
if (log_level_file)
config->log_level_file = log_level_file;
if (log_filename) if (log_filename)
config->log_filename = log_filename; config->log_filename = log_filename;
if (error_log_filename) if (error_log_filename)
@ -80,9 +85,9 @@ do_configure(bool show_only)
if (retention_window) if (retention_window)
config->retention_window = retention_window; config->retention_window = retention_window;
if (compress_alg != NOT_DEFINED_COMPRESS) if (compress_alg)
config->compress_alg = compress_alg; config->compress_alg = compress_alg;
if (compress_level != DEFAULT_COMPRESS_LEVEL) if (compress_level)
config->compress_level = compress_level; config->compress_level = compress_level;
if (show_only) if (show_only)
@ -107,21 +112,23 @@ pgBackupConfigInit(pgBackupConfig *config)
config->master_port = NULL; config->master_port = NULL;
config->master_db = NULL; config->master_db = NULL;
config->master_user = NULL; config->master_user = NULL;
config->replica_timeout = INT_MIN; /* INT_MIN means "undefined" */ config->replica_timeout = REPLICA_TIMEOUT_DEFAULT;
config->log_level_console = INT_MIN; /* INT_MIN means "undefined" */ config->archive_timeout = ARCHIVE_TIMEOUT_DEFAULT;
config->log_level_file = INT_MIN; /* INT_MIN means "undefined" */
config->log_filename = NULL; config->log_level_console = LOG_LEVEL_CONSOLE_DEFAULT;
config->log_level_file = LOG_LEVEL_FILE_DEFAULT;
config->log_filename = LOG_FILENAME_DEFAULT;
config->error_log_filename = NULL; config->error_log_filename = NULL;
config->log_directory = NULL; config->log_directory = LOG_DIRECTORY_DEFAULT;
config->log_rotation_size = 0; config->log_rotation_size = LOG_ROTATION_SIZE_DEFAULT;
config->log_rotation_age = 0; config->log_rotation_age = LOG_ROTATION_AGE_DEFAULT;
config->retention_redundancy = 0; config->retention_redundancy = RETENTION_REDUNDANCY_DEFAULT;
config->retention_window = 0; config->retention_window = RETENTION_WINDOW_DEFAULT;
config->compress_alg = NOT_DEFINED_COMPRESS; config->compress_alg = COMPRESS_ALG_DEFAULT;
config->compress_level = DEFAULT_COMPRESS_LEVEL; config->compress_level = COMPRESS_LEVEL_DEFAULT;
} }
void void
@ -154,55 +161,43 @@ writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
if (config->master_user) if (config->master_user)
fprintf(out, "master-user = %s\n", config->master_user); fprintf(out, "master-user = %s\n", config->master_user);
if (config->replica_timeout != INT_MIN) convert_from_base_unit_u(config->replica_timeout, OPTION_UNIT_S,
{ &res, &unit);
convert_from_base_unit_u(config->replica_timeout, OPTION_UNIT_S, fprintf(out, "replica-timeout = " UINT64_FORMAT "%s\n", res, unit);
&res, &unit);
fprintf(out, "replica-timeout = " UINT64_FORMAT "%s\n", res, unit); fprintf(out, "#Archive parameters:\n");
} convert_from_base_unit_u(config->archive_timeout, OPTION_UNIT_S,
&res, &unit);
fprintf(out, "archive-timeout = " UINT64_FORMAT "%s\n", res, unit);
fprintf(out, "#Logging parameters:\n"); fprintf(out, "#Logging parameters:\n");
if (config->log_level_console != INT_MIN) fprintf(out, "log-level-console = %s\n", deparse_log_level(config->log_level_console));
fprintf(out, "log-level-console = %s\n", deparse_log_level(config->log_level_console)); fprintf(out, "log-level-file = %s\n", deparse_log_level(config->log_level_file));
if (config->log_level_file != INT_MIN) fprintf(out, "log-filename = %s\n", config->log_filename);
fprintf(out, "log-level-file = %s\n", deparse_log_level(config->log_level_file));
if (config->log_filename)
fprintf(out, "log-filename = %s\n", config->log_filename);
if (config->error_log_filename) if (config->error_log_filename)
fprintf(out, "error-log-filename = %s\n", config->error_log_filename); fprintf(out, "error-log-filename = %s\n", config->error_log_filename);
if (config->log_directory)
fprintf(out, "log-directory = %s\n", config->log_directory);
/* if (strcmp(config->log_directory, LOG_DIRECTORY_DEFAULT) == 0)
* Convert values from base unit fprintf(out, "log-directory = %s/%s\n", backup_path, config->log_directory);
*/ else
if (config->log_rotation_size) fprintf(out, "log-directory = %s\n", config->log_directory);
{ /* Convert values from base unit */
convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB, convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB,
&res, &unit); &res, &unit);
fprintf(out, "log-rotation-size = " UINT64_FORMAT "%s\n", res, unit); fprintf(out, "log-rotation-size = " UINT64_FORMAT "%s\n", res, (res)?unit:"KB");
}
if (config->log_rotation_age) convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S,
{ &res, &unit);
convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S, fprintf(out, "log-rotation-age = " UINT64_FORMAT "%s\n", res, (res)?unit:"min");
&res, &unit);
fprintf(out, "log-rotation-age = " UINT64_FORMAT "%s\n", res, unit);
}
fprintf(out, "#Retention parameters:\n"); fprintf(out, "#Retention parameters:\n");
if (config->retention_redundancy) fprintf(out, "retention-redundancy = %u\n", config->retention_redundancy);
fprintf(out, "retention-redundancy = %u\n", config->retention_redundancy); fprintf(out, "retention-window = %u\n", config->retention_window);
if (config->retention_window)
fprintf(out, "retention-window = %u\n", config->retention_window);
fprintf(out, "#Compression parameters:\n"); fprintf(out, "#Compression parameters:\n");
fprintf(out, "compress-algorithm = %s\n", deparse_compress_alg(config->compress_alg)); fprintf(out, "compress-algorithm = %s\n", deparse_compress_alg(config->compress_alg));
fprintf(out, "compress-level = %d\n", config->compress_level);
if (compress_level != config->compress_level)
fprintf(out, "compress-level = %d\n", compress_level);
else
fprintf(out, "compress-level = %d\n", config->compress_level);
} }
void void
@ -258,6 +253,8 @@ readBackupCatalogConfigFile(void)
{ 'u', 0, "replica-timeout", &(config->replica_timeout), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_S }, { 'u', 0, "replica-timeout", &(config->replica_timeout), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_S },
/* other options */ /* other options */
{ 'U', 0, "system-identifier", &(config->system_identifier), SOURCE_FILE_STRICT }, { 'U', 0, "system-identifier", &(config->system_identifier), SOURCE_FILE_STRICT },
/* archive options */
{ 'u', 0, "archive-timeout", &(config->archive_timeout), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_S },
{0} {0}
}; };
@ -342,6 +339,8 @@ static void
show_configure_json(pgBackupConfig *config) show_configure_json(pgBackupConfig *config)
{ {
PQExpBuffer buf = &show_buf; PQExpBuffer buf = &show_buf;
uint64 res;
const char *unit;
json_add(buf, JT_BEGIN_OBJECT, &json_level); json_add(buf, JT_BEGIN_OBJECT, &json_level);
@ -373,53 +372,60 @@ show_configure_json(pgBackupConfig *config)
json_add_value(buf, "master-user", config->master_user, json_level, json_add_value(buf, "master-user", config->master_user, json_level,
true); true);
if (config->replica_timeout != INT_MIN) json_add_key(buf, "replica-timeout", json_level, true);
{ convert_from_base_unit_u(config->replica_timeout, OPTION_UNIT_S,
json_add_key(buf, "replica-timeout", json_level, true); &res, &unit);
appendPQExpBuffer(buf, "%d", config->replica_timeout); appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, unit);
}
/* Archive parameters */
json_add_key(buf, "archive-timeout", json_level, true);
convert_from_base_unit_u(config->archive_timeout, OPTION_UNIT_S,
&res, &unit);
appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, unit);
/* Logging parameters */ /* Logging parameters */
if (config->log_level_console != INT_MIN) json_add_value(buf, "log-level-console",
json_add_value(buf, "log-level-console", deparse_log_level(config->log_level_console), json_level,
deparse_log_level(config->log_level_console), json_level, true);
true); json_add_value(buf, "log-level-file",
if (config->log_level_file != INT_MIN) deparse_log_level(config->log_level_file), json_level,
json_add_value(buf, "log-level-file", true);
deparse_log_level(config->log_level_file), json_level, json_add_value(buf, "log-filename", config->log_filename, json_level,
true); true);
if (config->log_filename)
json_add_value(buf, "log-filename", config->log_filename, json_level,
true);
if (config->error_log_filename) if (config->error_log_filename)
json_add_value(buf, "error-log-filename", config->error_log_filename, json_add_value(buf, "error-log-filename", config->error_log_filename,
json_level, true); json_level, true);
if (config->log_directory)
json_add_value(buf, "log-directory", config->log_directory, json_level,
true);
if (config->log_rotation_size) if (strcmp(config->log_directory, LOG_DIRECTORY_DEFAULT) == 0)
{ {
json_add_key(buf, "log-rotation-size", json_level, true); char log_directory_fullpath[MAXPGPATH];
appendPQExpBuffer(buf, "%d", config->log_rotation_size);
} sprintf(log_directory_fullpath, "%s/%s",
if (config->log_rotation_age) backup_path, config->log_directory);
{
json_add_key(buf, "log-rotation-age", json_level, true); json_add_value(buf, "log-directory", log_directory_fullpath,
appendPQExpBuffer(buf, "%d", config->log_rotation_age); json_level, true);
} }
else
json_add_value(buf, "log-directory", config->log_directory,
json_level, true);
json_add_key(buf, "log-rotation-size", json_level, true);
convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB,
&res, &unit);
appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, (res)?unit:"KB");
json_add_key(buf, "log-rotation-age", json_level, true);
convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S,
&res, &unit);
appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, (res)?unit:"min");
/* Retention parameters */ /* Retention parameters */
if (config->retention_redundancy) json_add_key(buf, "retention-redundancy", json_level, true);
{ appendPQExpBuffer(buf, "%u", config->retention_redundancy);
json_add_key(buf, "retention-redundancy", json_level, true);
appendPQExpBuffer(buf, "%u", config->retention_redundancy); json_add_key(buf, "retention-window", json_level, true);
} appendPQExpBuffer(buf, "%u", config->retention_window);
if (config->retention_window)
{
json_add_key(buf, "retention-window", json_level, true);
appendPQExpBuffer(buf, "%u", config->retention_window);
}
/* Compression parameters */ /* Compression parameters */
json_add_value(buf, "compress-algorithm", json_add_value(buf, "compress-algorithm",

View File

@ -141,7 +141,8 @@ do_retention_purge(void)
if (retention_window > 0) if (retention_window > 0)
elog(LOG, "WINDOW=%u", retention_window); elog(LOG, "WINDOW=%u", retention_window);
if (retention_redundancy == 0 && retention_window == 0) if (retention_redundancy == 0
&& retention_window == 0)
{ {
elog(WARNING, "Retention policy is not set"); elog(WARNING, "Retention policy is not set");
if (!delete_wal) if (!delete_wal)
@ -161,7 +162,8 @@ do_retention_purge(void)
} }
/* Find target backups to be deleted */ /* Find target backups to be deleted */
if (delete_expired && (retention_redundancy > 0 || retention_window > 0)) if (delete_expired &&
(retention_redundancy > 0 || retention_window > 0))
{ {
backup_num = 0; backup_num = 0;
for (i = 0; i < parray_num(backup_list); i++) for (i = 0; i < parray_num(backup_list); i++)
@ -173,13 +175,13 @@ do_retention_purge(void)
if (backup->status != BACKUP_STATUS_OK) if (backup->status != BACKUP_STATUS_OK)
continue; continue;
/* /*
* When a validate full backup was found, we can delete the * When a valid full backup was found, we can delete the
* backup that is older than it using the number of generations. * backup that is older than it using the number of generations.
*/ */
if (backup->backup_mode == BACKUP_MODE_FULL) if (backup->backup_mode == BACKUP_MODE_FULL)
backup_num++; backup_num++;
/* Evaluateretention_redundancy if this backup is eligible for removal */ /* Evaluate retention_redundancy if this backup is eligible for removal */
if (keep_next_backup || if (keep_next_backup ||
retention_redundancy >= backup_num_evaluate + 1 || retention_redundancy >= backup_num_evaluate + 1 ||
(retention_window > 0 && backup->recovery_time >= days_threshold)) (retention_window > 0 && backup->recovery_time >= days_threshold))
@ -200,6 +202,7 @@ do_retention_purge(void)
continue; continue;
} }
/* Delete backup and update status to DELETED */ /* Delete backup and update status to DELETED */
pgBackupDeleteFiles(backup); pgBackupDeleteFiles(backup);
backup_deleted = true; backup_deleted = true;
@ -259,7 +262,8 @@ pgBackupDeleteFiles(pgBackup *backup)
time2iso(timestamp, lengthof(timestamp), backup->recovery_time); time2iso(timestamp, lengthof(timestamp), backup->recovery_time);
elog(INFO, "delete: %s %s", base36enc(backup->start_time), timestamp); elog(INFO, "delete: %s %s",
base36enc(backup->start_time), timestamp);
/* /*
* Update STATUS to BACKUP_STATUS_DELETING in preparation for the case which * Update STATUS to BACKUP_STATUS_DELETING in preparation for the case which

View File

@ -87,6 +87,7 @@ help_pg_probackup(void)
printf(_(" [--master-db=db_name] [--master-host=host_name]\n")); printf(_(" [--master-db=db_name] [--master-host=host_name]\n"));
printf(_(" [--master-port=port] [--master-user=user_name]\n")); printf(_(" [--master-port=port] [--master-user=user_name]\n"));
printf(_(" [--replica-timeout=timeout]\n")); printf(_(" [--replica-timeout=timeout]\n"));
printf(_(" [--archive-timeout=timeout]\n"));
printf(_("\n %s show-config -B backup-dir --instance=instance_name\n"), PROGRAM_NAME); printf(_("\n %s show-config -B backup-dir --instance=instance_name\n"), PROGRAM_NAME);
printf(_(" [--format=format]\n")); printf(_(" [--format=format]\n"));
@ -257,7 +258,7 @@ help_backup(void)
printf(_(" --master-db=db_name database to connect to master\n")); printf(_(" --master-db=db_name database to connect to master\n"));
printf(_(" --master-host=host_name database server host of master\n")); printf(_(" --master-host=host_name database server host of master\n"));
printf(_(" --master-port=port database server port of master\n")); printf(_(" --master-port=port database server port of master\n"));
printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication in seconds\n")); printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication (default: 5min)\n"));
} }
static void static void
@ -429,6 +430,7 @@ help_set_config(void)
printf(_(" [--master-db=db_name] [--master-host=host_name]\n")); printf(_(" [--master-db=db_name] [--master-host=host_name]\n"));
printf(_(" [--master-port=port] [--master-user=user_name]\n")); printf(_(" [--master-port=port] [--master-user=user_name]\n"));
printf(_(" [--replica-timeout=timeout]\n\n")); printf(_(" [--replica-timeout=timeout]\n\n"));
printf(_(" [--archive-timeout=timeout]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" --instance=instance_name name of the instance\n")); printf(_(" --instance=instance_name name of the instance\n"));
@ -477,7 +479,9 @@ help_set_config(void)
printf(_(" --master-db=db_name database to connect to master\n")); printf(_(" --master-db=db_name database to connect to master\n"));
printf(_(" --master-host=host_name database server host of master\n")); printf(_(" --master-host=host_name database server host of master\n"));
printf(_(" --master-port=port database server port of master\n")); printf(_(" --master-port=port database server port of master\n"));
printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication\n")); printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication (default: 5min)\n"));
printf(_("\n Archive options:\n"));
printf(_(" --archive-timeout=timeout wait timeout for WAL segment archiving (default: 5min)\n"));
} }
static void static void

View File

@ -51,12 +51,12 @@ bool backup_logs = false;
bool smooth_checkpoint; bool smooth_checkpoint;
bool is_remote_backup = false; bool is_remote_backup = false;
/* Wait timeout for WAL segment archiving */ /* Wait timeout for WAL segment archiving */
uint32 archive_timeout = 300; /* default is 300 seconds */ uint32 archive_timeout = ARCHIVE_TIMEOUT_DEFAULT;
const char *master_db = NULL; const char *master_db = NULL;
const char *master_host = NULL; const char *master_host = NULL;
const char *master_port= NULL; const char *master_port= NULL;
const char *master_user = NULL; const char *master_user = NULL;
uint32 replica_timeout = 300; /* default is 300 seconds */ uint32 replica_timeout = REPLICA_TIMEOUT_DEFAULT;
/* restore options */ /* restore options */
static char *target_time; static char *target_time;
@ -84,9 +84,10 @@ uint32 retention_redundancy = 0;
uint32 retention_window = 0; uint32 retention_window = 0;
/* compression options */ /* compression options */
CompressAlg compress_alg = NOT_DEFINED_COMPRESS; CompressAlg compress_alg = COMPRESS_ALG_DEFAULT;
int compress_level = DEFAULT_COMPRESS_LEVEL; int compress_level = COMPRESS_LEVEL_DEFAULT;
bool compress_shortcut = false; bool compress_shortcut = false;
/* other options */ /* other options */
char *instance_name; char *instance_name;
@ -571,7 +572,7 @@ compress_init(void)
if (backup_subcmd != SET_CONFIG_CMD) if (backup_subcmd != SET_CONFIG_CMD)
{ {
if (compress_level != DEFAULT_COMPRESS_LEVEL if (compress_level != COMPRESS_LEVEL_DEFAULT
&& compress_alg == NOT_DEFINED_COMPRESS) && compress_alg == NOT_DEFINED_COMPRESS)
elog(ERROR, "Cannot specify compress-level option without compress-alg option"); elog(ERROR, "Cannot specify compress-level option without compress-alg option");
} }

View File

@ -63,6 +63,8 @@
#define PG_BLACK_LIST "black_list" #define PG_BLACK_LIST "black_list"
#define PG_TABLESPACE_MAP_FILE "tablespace_map" #define PG_TABLESPACE_MAP_FILE "tablespace_map"
#define LOG_FILENAME_DEFAULT "pg_probackup.log"
#define LOG_DIRECTORY_DEFAULT "log"
/* Direcotry/File permission */ /* Direcotry/File permission */
#define DIR_PERMISSION (0700) #define DIR_PERMISSION (0700)
#define FILE_PERMISSION (0600) #define FILE_PERMISSION (0600)
@ -182,6 +184,8 @@ typedef struct pgBackupConfig
const char *master_user; const char *master_user;
int replica_timeout; int replica_timeout;
int archive_timeout;
int log_level_console; int log_level_console;
int log_level_file; int log_level_file;
char *log_filename; char *log_filename;
@ -337,12 +341,14 @@ extern char *replication_slot;
/* backup options */ /* backup options */
extern bool smooth_checkpoint; extern bool smooth_checkpoint;
#define ARCHIVE_TIMEOUT_DEFAULT 300
extern uint32 archive_timeout; extern uint32 archive_timeout;
extern bool is_remote_backup; extern bool is_remote_backup;
extern const char *master_db; extern const char *master_db;
extern const char *master_host; extern const char *master_host;
extern const char *master_port; extern const char *master_port;
extern const char *master_user; extern const char *master_user;
#define REPLICA_TIMEOUT_DEFAULT 300
extern uint32 replica_timeout; extern uint32 replica_timeout;
extern bool is_ptrack_support; extern bool is_ptrack_support;
@ -358,7 +364,10 @@ extern bool delete_expired;
extern bool apply_to_all; extern bool apply_to_all;
extern bool force_delete; extern bool force_delete;
/* retention options */ /* retention options. 0 disables the option */
#define RETENTION_REDUNDANCY_DEFAULT 0
#define RETENTION_WINDOW_DEFAULT 0
extern uint32 retention_redundancy; extern uint32 retention_redundancy;
extern uint32 retention_window; extern uint32 retention_window;
@ -367,7 +376,8 @@ extern CompressAlg compress_alg;
extern int compress_level; extern int compress_level;
extern bool compress_shortcut; extern bool compress_shortcut;
#define DEFAULT_COMPRESS_LEVEL 1 #define COMPRESS_ALG_DEFAULT NOT_DEFINED_COMPRESS
#define COMPRESS_LEVEL_DEFAULT 1
extern CompressAlg parse_compress_alg(const char *arg); extern CompressAlg parse_compress_alg(const char *arg);
extern const char* deparse_compress_alg(int alg); extern const char* deparse_compress_alg(int alg);

View File

@ -14,8 +14,10 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h>
#include "catalog/pg_control.h" #include "catalog/pg_control.h"
#include "utils/logger.h"
#include "utils/thread.h" #include "utils/thread.h"
typedef struct typedef struct
@ -455,7 +457,7 @@ restore_backup(pgBackup *backup)
parray_walk(files, pgFileFree); parray_walk(files, pgFileFree);
parray_free(files); parray_free(files);
if (LOG_LEVEL_CONSOLE <= LOG || LOG_LEVEL_FILE <= LOG) if (log_level_console <= LOG || log_level_file <= LOG)
elog(LOG, "restore %s backup completed", base36enc(backup->start_time)); elog(LOG, "restore %s backup completed", base36enc(backup->start_time));
} }
@ -492,7 +494,7 @@ remove_deleted_files(pgBackup *backup)
if (parray_bsearch(files, file, pgFileComparePathDesc) == NULL) if (parray_bsearch(files, file, pgFileComparePathDesc) == NULL)
{ {
pgFileDelete(file); pgFileDelete(file);
if (LOG_LEVEL_CONSOLE <= LOG || LOG_LEVEL_FILE <= LOG) if (log_level_console <= LOG || log_level_file <= LOG)
elog(LOG, "deleted %s", GetRelativePath(file->path, pgdata)); elog(LOG, "deleted %s", GetRelativePath(file->path, pgdata));
} }
} }
@ -667,7 +669,7 @@ check_tablespace_mapping(pgBackup *backup)
pgBackupGetPath(backup, this_backup_path, lengthof(this_backup_path), NULL); pgBackupGetPath(backup, this_backup_path, lengthof(this_backup_path), NULL);
read_tablespace_map(links, this_backup_path); read_tablespace_map(links, this_backup_path);
if (LOG_LEVEL_CONSOLE <= LOG || LOG_LEVEL_FILE <= LOG) if (log_level_console <= LOG || log_level_file <= LOG)
elog(LOG, "check tablespace directories of backup %s", elog(LOG, "check tablespace directories of backup %s",
base36enc(backup->start_time)); base36enc(backup->start_time));

View File

@ -341,8 +341,8 @@ pgBackup_init(pgBackup *backup)
backup->data_bytes = BYTES_INVALID; backup->data_bytes = BYTES_INVALID;
backup->wal_bytes = BYTES_INVALID; backup->wal_bytes = BYTES_INVALID;
backup->compress_alg = NOT_DEFINED_COMPRESS; backup->compress_alg = COMPRESS_ALG_DEFAULT;
backup->compress_level = 0; backup->compress_level = COMPRESS_LEVEL_DEFAULT;
backup->block_size = BLCKSZ; backup->block_size = BLCKSZ;
backup->wal_block_size = XLOG_BLCKSZ; backup->wal_block_size = XLOG_BLCKSZ;

View File

@ -15,12 +15,13 @@
#include "logger.h" #include "logger.h"
#include "pgut.h" #include "pgut.h"
#include "pg_probackup.h"
#include "thread.h" #include "thread.h"
/* Logger parameters */ /* Logger parameters */
int log_level_console = LOG_NONE; int log_level_console = LOG_LEVEL_CONSOLE_DEFAULT;
int log_level_file = LOG_NONE; int log_level_file = LOG_LEVEL_FILE_DEFAULT;
char *log_filename = NULL; char *log_filename = NULL;
char *error_log_filename = NULL; char *error_log_filename = NULL;
@ -74,12 +75,12 @@ void
init_logger(const char *root_path) init_logger(const char *root_path)
{ {
/* Set log path */ /* Set log path */
if (LOG_LEVEL_FILE != LOG_OFF || error_log_filename) if (log_level_file != LOG_OFF || error_log_filename)
{ {
if (log_directory) if (log_directory)
strcpy(log_path, log_directory); strcpy(log_path, log_directory);
else else
join_path_components(log_path, root_path, "log"); join_path_components(log_path, root_path, LOG_DIRECTORY_DEFAULT);
} }
} }
@ -165,10 +166,10 @@ elog_internal(int elevel, bool file_only, const char *fmt, va_list args)
time_t log_time = (time_t) time(NULL); time_t log_time = (time_t) time(NULL);
char strfbuf[128]; char strfbuf[128];
write_to_file = elevel >= LOG_LEVEL_FILE && log_path[0] != '\0'; write_to_file = elevel >= log_level_file && log_path[0] != '\0';
write_to_error_log = elevel >= ERROR && error_log_filename && write_to_error_log = elevel >= ERROR && error_log_filename &&
log_path[0] != '\0'; log_path[0] != '\0';
write_to_stderr = elevel >= LOG_LEVEL_CONSOLE && !file_only; write_to_stderr = elevel >= log_level_console && !file_only;
pthread_lock(&log_file_mutex); pthread_lock(&log_file_mutex);
#ifdef WIN32 #ifdef WIN32
@ -201,7 +202,7 @@ elog_internal(int elevel, bool file_only, const char *fmt, va_list args)
if (log_file == NULL) if (log_file == NULL)
{ {
if (log_filename == NULL) if (log_filename == NULL)
open_logfile(&log_file, "pg_probackup.log"); open_logfile(&log_file, LOG_FILENAME_DEFAULT);
else else
open_logfile(&log_file, log_filename); open_logfile(&log_file, log_filename);
} }
@ -271,7 +272,7 @@ elog_stderr(int elevel, const char *fmt, ...)
* Do not log message if severity level is less than log_level. * Do not log message if severity level is less than log_level.
* It is the little optimisation to put it here not in elog_internal(). * It is the little optimisation to put it here not in elog_internal().
*/ */
if (elevel < LOG_LEVEL_CONSOLE && elevel < ERROR) if (elevel < log_level_console && elevel < ERROR)
return; return;
va_start(args, fmt); va_start(args, fmt);
@ -298,7 +299,7 @@ elog(int elevel, const char *fmt, ...)
* Do not log message if severity level is less than log_level. * Do not log message if severity level is less than log_level.
* It is the little optimisation to put it here not in elog_internal(). * It is the little optimisation to put it here not in elog_internal().
*/ */
if (elevel < LOG_LEVEL_CONSOLE && elevel < LOG_LEVEL_FILE && elevel < ERROR) if (elevel < log_level_console && elevel < log_level_file && elevel < ERROR)
return; return;
va_start(args, fmt); va_start(args, fmt);
@ -318,7 +319,7 @@ elog_file(int elevel, const char *fmt, ...)
* Do not log message if severity level is less than log_level. * Do not log message if severity level is less than log_level.
* It is the little optimisation to put it here not in elog_internal(). * It is the little optimisation to put it here not in elog_internal().
*/ */
if (elevel < LOG_LEVEL_FILE && elevel < ERROR) if (elevel < log_level_file && elevel < ERROR)
return; return;
va_start(args, fmt); va_start(args, fmt);
@ -359,7 +360,7 @@ pg_log(eLogType type, const char *fmt, ...)
* Do not log message if severity level is less than log_level. * Do not log message if severity level is less than log_level.
* It is the little optimisation to put it here not in elog_internal(). * It is the little optimisation to put it here not in elog_internal().
*/ */
if (elevel < LOG_LEVEL_CONSOLE && elevel < LOG_LEVEL_FILE && elevel < ERROR) if (elevel < log_level_console && elevel < log_level_file && elevel < ERROR)
return; return;
va_start(args, fmt); va_start(args, fmt);

View File

@ -36,11 +36,13 @@ extern char *error_log_filename;
extern char *log_directory; extern char *log_directory;
extern char log_path[MAXPGPATH]; extern char log_path[MAXPGPATH];
#define LOG_ROTATION_SIZE_DEFAULT 0
#define LOG_ROTATION_AGE_DEFAULT 0
extern int log_rotation_size; extern int log_rotation_size;
extern int log_rotation_age; extern int log_rotation_age;
#define LOG_LEVEL_CONSOLE ((log_level_console == LOG_NONE) ? INFO : log_level_console) #define LOG_LEVEL_CONSOLE_DEFAULT INFO
#define LOG_LEVEL_FILE ((log_level_file == LOG_NONE) ? LOG_OFF : log_level_file) #define LOG_LEVEL_FILE_DEFAULT LOG_OFF
#undef elog #undef elog
extern void elog(int elevel, const char *fmt, ...) pg_attribute_printf(2, 3); extern void elog(int elevel, const char *fmt, ...) pg_attribute_printf(2, 3);

View File

@ -1680,7 +1680,7 @@ pgut_execute_parallel(PGconn* conn,
elog(ERROR, "interrupted"); elog(ERROR, "interrupted");
/* write query to elog if verbose */ /* write query to elog if verbose */
if (LOG_LEVEL_CONSOLE <= VERBOSE || LOG_LEVEL_FILE <= VERBOSE) if (log_level_console <= VERBOSE || log_level_file <= VERBOSE)
{ {
int i; int i;
@ -1742,7 +1742,7 @@ pgut_execute_extended(PGconn* conn, const char *query, int nParams,
elog(ERROR, "interrupted"); elog(ERROR, "interrupted");
/* write query to elog if verbose */ /* write query to elog if verbose */
if (LOG_LEVEL_CONSOLE <= VERBOSE || LOG_LEVEL_FILE <= VERBOSE) if (log_level_console <= VERBOSE || log_level_file <= VERBOSE)
{ {
int i; int i;
@ -1800,7 +1800,7 @@ pgut_send(PGconn* conn, const char *query, int nParams, const char **params, int
elog(ERROR, "interrupted"); elog(ERROR, "interrupted");
/* write query to elog if verbose */ /* write query to elog if verbose */
if (LOG_LEVEL_CONSOLE <= VERBOSE || LOG_LEVEL_FILE <= VERBOSE) if (log_level_console <= VERBOSE || log_level_file <= VERBOSE)
{ {
int i; int i;