1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-11 11:41:33 +02:00

pg_probackup reads logging options

This commit is contained in:
Arthur Zakirov 2017-04-27 14:09:44 +03:00
parent ea4ff53e3d
commit 9e8b171116
4 changed files with 126 additions and 55 deletions

View File

@ -103,15 +103,24 @@ readBackupCatalogConfigFile(void)
pgut_option options[] =
{
/* configure options */
{ 'U', 0, "system-identifier", &(config->system_identifier), SOURCE_FILE_STRICT },
/* retention options */
{ 'u', 0, "retention-redundancy", &(config->retention_redundancy),SOURCE_FILE_STRICT },
{ 'u', 0, "retention-window", &(config->retention_window), SOURCE_FILE_STRICT },
/* logging options */
// { 'f', 40, "log-level", opt_log_level, SOURCE_CMDLINE },
// { 's', 41, "log-filename", &log_filename, SOURCE_CMDLINE },
// { 's', 42, "error-log-filename", &error_log_filename, SOURCE_CMDLINE },
// { 's', 43, "log-directory", &log_directory, SOURCE_CMDLINE },
// { 'u', 44, "log-rotation-size", &log_rotation_size, SOURCE_CMDLINE },
// { 'u', 45, "log-rotation-age", &log_rotation_age, SOURCE_CMDLINE },
/* connection options */
{ 's', 0, "pgdata", &(config->pgdata), SOURCE_FILE_STRICT },
{ 's', 0, "pgdatabase", &(config->pgdatabase), SOURCE_FILE_STRICT },
{ 's', 0, "pghost", &(config->pghost), SOURCE_FILE_STRICT },
{ 's', 0, "pgport", &(config->pgport), SOURCE_FILE_STRICT },
{ 's', 0, "pguser", &(config->pguser), SOURCE_FILE_STRICT },
{ 'u', 0, "retention-redundancy", &(config->retention_redundancy),SOURCE_FILE_STRICT },
{ 'u', 0, "retention-window", &(config->retention_window), SOURCE_FILE_STRICT },
/* other options */
{ 'U', 0, "system-identifier", &(config->system_identifier), SOURCE_FILE_STRICT },
{0}
};

View File

@ -21,34 +21,35 @@ const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
/* path configuration */
char *backup_path;
char *pgdata;
char arclog_path[MAXPGPATH];
char *backup_path = NULL;
char *pgdata = NULL;
char arclog_path[MAXPGPATH] = "";
/* directory configuration */
pgBackup current;
ProbackupSubcmd backup_subcmd;
ProbackupSubcmd backup_subcmd;
bool help = false;
bool help = false;
char *backup_id_string_param = NULL;
bool backup_logs = false;
char *backup_id_string_param = NULL;
bool backup_logs = false;
bool smooth_checkpoint;
int num_threads = 1;
bool stream_wal = false;
bool from_replica = false;
bool progress = false;
bool delete_wal = false;
bool delete_expired = false;
bool apply_to_all = false;
bool force_delete = false;
uint32 archive_timeout = 300; /* Wait timeout for WAL segment archiving */
bool smooth_checkpoint;
int num_threads = 1;
bool stream_wal = false;
bool from_replica = false;
bool progress = false;
bool delete_wal = false;
bool delete_expired = false;
bool apply_to_all = false;
bool force_delete = false;
/* Wait timeout for WAL segment archiving */
uint32 archive_timeout = 300;
uint64 system_identifier = 0;
uint64 system_identifier = 0;
uint32 retention_redundancy = 0;
uint32 retention_window = 0;
uint32 retention_redundancy = 0;
uint32 retention_window = 0;
/* restore configuration */
static char *target_time;
@ -57,48 +58,56 @@ static char *target_inclusive;
static TimeLineID target_tli;
static void opt_backup_mode(pgut_option *opt, const char *arg);
static void opt_log_level(pgut_option *opt, const char *arg);
static pgut_option options[] =
{
/* directory options */
{ 'b', 1, "help", &help, SOURCE_CMDLINE },
{ 's', 'D', "pgdata", &pgdata, SOURCE_CMDLINE },
{ 's', 'B', "backup-path", &backup_path, SOURCE_CMDLINE },
{ 'b', 1, "help", &help, SOURCE_CMDLINE },
{ 's', 'D', "pgdata", &pgdata, SOURCE_CMDLINE },
{ 's', 'B', "backup-path", &backup_path, SOURCE_CMDLINE },
/* common options */
{ 'u', 'j', "threads", &num_threads, SOURCE_CMDLINE },
{ 'b', 8, "stream", &stream_wal, SOURCE_CMDLINE },
{ 'b', 11, "progress", &progress, SOURCE_CMDLINE },
{ 'u', 'j', "threads", &num_threads, SOURCE_CMDLINE },
{ 'b', 1, "stream", &stream_wal, SOURCE_CMDLINE },
{ 'b', 2, "progress", &progress, SOURCE_CMDLINE },
{ 's', 'i', "backup-id", &backup_id_string_param, SOURCE_CMDLINE },
/* backup options */
{ 'b', 10, "backup-pg-log", &backup_logs, SOURCE_CMDLINE },
{ 'b', 10, "backup-pg-log", &backup_logs, SOURCE_CMDLINE },
{ 'f', 'b', "backup-mode", opt_backup_mode, SOURCE_CMDLINE },
{ 'b', 'C', "smooth-checkpoint", &smooth_checkpoint, SOURCE_CMDLINE },
{ 's', 'S', "slot", &replication_slot, SOURCE_CMDLINE },
{ 'u', 2, "archive-timeout", &archive_timeout, SOURCE_CMDLINE },
{ 'b', 19, "delete-expired", &delete_expired, SOURCE_CMDLINE },
{ 'u', 11, "archive-timeout", &archive_timeout, SOURCE_CMDLINE },
{ 'b', 12, "delete-expired", &delete_expired, SOURCE_CMDLINE },
/* restore options */
{ 's', 3, "time", &target_time, SOURCE_CMDLINE },
{ 's', 4, "xid", &target_xid, SOURCE_CMDLINE },
{ 's', 5, "inclusive", &target_inclusive, SOURCE_CMDLINE },
{ 'u', 6, "timeline", &target_tli, SOURCE_CMDLINE },
{ 's', 20, "time", &target_time, SOURCE_CMDLINE },
{ 's', 21, "xid", &target_xid, SOURCE_CMDLINE },
{ 's', 22, "inclusive", &target_inclusive, SOURCE_CMDLINE },
{ 'u', 23, "timeline", &target_tli, SOURCE_CMDLINE },
{ 'f', 'T', "tablespace-mapping", opt_tablespace_map, SOURCE_CMDLINE },
/* delete options */
{ 'b', 12, "wal", &delete_wal, SOURCE_CMDLINE },
{ 'b', 16, "expired", &delete_expired, SOURCE_CMDLINE },
{ 'b', 17, "all", &apply_to_all, SOURCE_CMDLINE },
{ 'b', 30, "wal", &delete_wal, SOURCE_CMDLINE },
{ 'b', 31, "expired", &delete_expired, SOURCE_CMDLINE },
{ 'b', 32, "all", &apply_to_all, SOURCE_CMDLINE },
/* TODO not implemented yet */
{ 'b', 18, "force", &force_delete, SOURCE_CMDLINE },
/* configure options */
{ 'u', 13, "retention-redundancy", &retention_redundancy, SOURCE_CMDLINE },
{ 'u', 14, "retention-window", &retention_window, SOURCE_CMDLINE },
/* other */
{ 'U', 15, "system-identifier", &system_identifier, SOURCE_FILE_STRICT },
{ 's', 'd', "pgdatabase" , &pgut_dbname, SOURCE_CMDLINE },
{ 's', 'h', "pghost" , &host, SOURCE_CMDLINE },
{ 's', 'p', "pgport" , &port, SOURCE_CMDLINE },
{ 's', 'U', "pguser" , &username, SOURCE_CMDLINE },
{ 'B', 'w', "no-password" , &prompt_password, SOURCE_CMDLINE },
{ 'b', 33, "force", &force_delete, SOURCE_CMDLINE },
/* retention options */
{ 'u', 34, "retention-redundancy", &retention_redundancy, SOURCE_CMDLINE },
{ 'u', 35, "retention-window", &retention_window, SOURCE_CMDLINE },
/* logging options */
{ 'f', 40, "log-level", opt_log_level, SOURCE_CMDLINE },
{ 's', 41, "log-filename", &log_filename, SOURCE_CMDLINE },
{ 's', 42, "error-log-filename", &error_log_filename, SOURCE_CMDLINE },
{ 's', 43, "log-directory", &log_directory, SOURCE_CMDLINE },
{ 'u', 44, "log-rotation-size", &log_rotation_size, SOURCE_CMDLINE },
{ 'u', 45, "log-rotation-age", &log_rotation_age, SOURCE_CMDLINE },
/* connection options */
{ 's', 'd', "pgdatabase", &pgut_dbname, SOURCE_CMDLINE },
{ 's', 'h', "pghost", &host, SOURCE_CMDLINE },
{ 's', 'p', "pgport", &port, SOURCE_CMDLINE },
{ 's', 'U', "pguser", &username, SOURCE_CMDLINE },
{ 'B', 'w', "no-password", &prompt_password, SOURCE_CMDLINE },
/* other options */
{ 'U', 50, "system-identifier", &system_identifier, SOURCE_FILE_STRICT },
{ 0 }
};
@ -202,6 +211,15 @@ main(int argc, char *argv[])
if (!is_absolute_path(backup_path))
elog(ERROR, "-B, --backup-path must be an absolute path");
/* Set log path */
if (log_filename || error_log_filename)
{
if (log_directory)
join_path_components(log_path, backup_path, log_directory);
else
join_path_components(log_path, backup_path, "log");
}
if (backup_id_string_param != NULL)
{
current.backup_id = base36dec(backup_id_string_param);
@ -228,9 +246,6 @@ main(int argc, char *argv[])
join_path_components(arclog_path, backup_path, "wal");
log_filename = "pg_probackup-%Y-%m-%d_%H%M%S.log";
join_path_components(log_path, backup_path, "log");
/* setup exclusion list for file search */
if (!backup_logs)
{
@ -292,3 +307,9 @@ opt_backup_mode(pgut_option *opt, const char *arg)
{
current.backup_mode = parse_backup_mode(arg);
}
static void
opt_log_level(pgut_option *opt, const char *arg)
{
log_level = parse_log_level(arg);
}

View File

@ -204,6 +204,45 @@ pg_log(eLogType type, const char *fmt, ...)
va_end(args);
}
/*
* Parses string representation of log level.
*/
int
parse_log_level(const char *level)
{
const char *v = level;
size_t len;
/* Skip all spaces detected */
while (isspace((unsigned char)*v))
v++;
len = strlen(v);
if (len == 0)
elog(ERROR, "log-level is empty");
if (pg_strncasecmp("verbose", v, len) == 0)
return VERBOSE;
else if (pg_strncasecmp("log", v, len) == 0)
return LOG;
else if (pg_strncasecmp("info", v, len) == 0)
return INFO;
else if (pg_strncasecmp("notice", v, len) == 0)
return NOTICE;
else if (pg_strncasecmp("warning", v, len) == 0)
return WARNING;
else if (pg_strncasecmp("error", v, len) == 0)
return ERROR;
else if (pg_strncasecmp("fatal", v, len) == 0)
return FATAL;
else if (pg_strncasecmp("panic", v, len) == 0)
return PANIC;
/* Log level is invalid */
elog(ERROR, "invalid log-level \"%s\"", level);
return 0;
}
/*
* Construct logfile name using timestamp information.
*

View File

@ -37,4 +37,6 @@ extern int log_rotation_age;
#undef elog
extern void elog(int elevel, const char *fmt, ...) pg_attribute_printf(2, 3);
extern int parse_log_level(const char *level);
#endif /* LOGGER_H */