mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-12-03 09:59:53 +02:00
PGPRO-584: Save unit name within configuration file
This commit is contained in:
parent
a1eeef782e
commit
78b510e82a
@ -109,6 +109,9 @@ pgBackupConfigInit(pgBackupConfig *config)
|
|||||||
void
|
void
|
||||||
writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
|
writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
|
||||||
{
|
{
|
||||||
|
uint64 res;
|
||||||
|
const char *unit;
|
||||||
|
|
||||||
fprintf(out, "#Backup instance info\n");
|
fprintf(out, "#Backup instance info\n");
|
||||||
fprintf(out, "PGDATA = %s\n", config->pgdata);
|
fprintf(out, "PGDATA = %s\n", config->pgdata);
|
||||||
fprintf(out, "system-identifier = %li\n", config->system_identifier);
|
fprintf(out, "system-identifier = %li\n", config->system_identifier);
|
||||||
@ -146,10 +149,24 @@ writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
|
|||||||
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)
|
if (config->log_directory)
|
||||||
fprintf(out, "log-directory = %s\n", config->log_directory);
|
fprintf(out, "log-directory = %s\n", config->log_directory);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert values from base unit
|
||||||
|
*/
|
||||||
if (config->log_rotation_size)
|
if (config->log_rotation_size)
|
||||||
fprintf(out, "log-rotation-size = %d\n", config->log_rotation_size);
|
{
|
||||||
|
convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB,
|
||||||
|
&res, &unit);
|
||||||
|
fprintf(out, "log-rotation-size = " UINT64_FORMAT "%s\n",
|
||||||
|
res, unit);
|
||||||
|
}
|
||||||
if (config->log_rotation_age)
|
if (config->log_rotation_age)
|
||||||
fprintf(out, "log-rotation-age = %d\n", config->log_rotation_age);
|
{
|
||||||
|
convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S,
|
||||||
|
&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)
|
if (config->retention_redundancy)
|
||||||
|
@ -338,6 +338,97 @@ convert_to_base_unit_u(uint64 value, const char *unit,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a value in some base unit to a human-friendly unit. The output
|
||||||
|
* unit is chosen so that it's the greatest unit that can represent the value
|
||||||
|
* without loss. For example, if the base unit is GUC_UNIT_KB, 1024 is
|
||||||
|
* converted to 1 MB, but 1025 is represented as 1025 kB.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
convert_from_base_unit(int64 base_value, int base_unit,
|
||||||
|
int64 *value, const char **unit)
|
||||||
|
{
|
||||||
|
const unit_conversion *table;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
*unit = NULL;
|
||||||
|
|
||||||
|
if (base_unit & OPTION_UNIT_MEMORY)
|
||||||
|
table = memory_unit_conversion_table;
|
||||||
|
else
|
||||||
|
table = time_unit_conversion_table;
|
||||||
|
|
||||||
|
for (i = 0; *table[i].unit; i++)
|
||||||
|
{
|
||||||
|
if (base_unit == table[i].base_unit)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Accept the first conversion that divides the value evenly. We
|
||||||
|
* assume that the conversions for each base unit are ordered from
|
||||||
|
* greatest unit to the smallest!
|
||||||
|
*/
|
||||||
|
if (table[i].multiplier < 0)
|
||||||
|
{
|
||||||
|
*value = base_value * (-table[i].multiplier);
|
||||||
|
*unit = table[i].unit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (base_value % table[i].multiplier == 0)
|
||||||
|
{
|
||||||
|
*value = base_value / table[i].multiplier;
|
||||||
|
*unit = table[i].unit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(*unit != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unsigned variant of convert_from_base_unit()
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
convert_from_base_unit_u(uint64 base_value, int base_unit,
|
||||||
|
uint64 *value, const char **unit)
|
||||||
|
{
|
||||||
|
const unit_conversion *table;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
*unit = NULL;
|
||||||
|
|
||||||
|
if (base_unit & OPTION_UNIT_MEMORY)
|
||||||
|
table = memory_unit_conversion_table;
|
||||||
|
else
|
||||||
|
table = time_unit_conversion_table;
|
||||||
|
|
||||||
|
for (i = 0; *table[i].unit; i++)
|
||||||
|
{
|
||||||
|
if (base_unit == table[i].base_unit)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Accept the first conversion that divides the value evenly. We
|
||||||
|
* assume that the conversions for each base unit are ordered from
|
||||||
|
* greatest unit to the smallest!
|
||||||
|
*/
|
||||||
|
if (table[i].multiplier < 0)
|
||||||
|
{
|
||||||
|
*value = base_value * (-table[i].multiplier);
|
||||||
|
*unit = table[i].unit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (base_value % table[i].multiplier == 0)
|
||||||
|
{
|
||||||
|
*value = base_value / table[i].multiplier;
|
||||||
|
*unit = table[i].unit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(*unit != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_unit(char *unit_str, int flags, int64 value, int64 *base_value)
|
parse_unit(char *unit_str, int flags, int64 value, int64 *base_value)
|
||||||
{
|
{
|
||||||
|
@ -200,6 +200,11 @@ extern bool parse_time(const char *value, time_t *result);
|
|||||||
extern bool parse_int(const char *value, int *result, int flags,
|
extern bool parse_int(const char *value, int *result, int flags,
|
||||||
const char **hintmsg);
|
const char **hintmsg);
|
||||||
|
|
||||||
|
extern void convert_from_base_unit(int64 base_value, int base_unit,
|
||||||
|
int64 *value, const char **unit);
|
||||||
|
extern void convert_from_base_unit_u(uint64 base_value, int base_unit,
|
||||||
|
uint64 *value, const char **unit);
|
||||||
|
|
||||||
#define IsSpace(c) (isspace((unsigned char)(c)))
|
#define IsSpace(c) (isspace((unsigned char)(c)))
|
||||||
#define IsAlpha(c) (isalpha((unsigned char)(c)))
|
#define IsAlpha(c) (isalpha((unsigned char)(c)))
|
||||||
#define IsAlnum(c) (isalnum((unsigned char)(c)))
|
#define IsAlnum(c) (isalnum((unsigned char)(c)))
|
||||||
|
Loading…
Reference in New Issue
Block a user