mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-12-03 09:59:53 +02:00
PGPRO-692: Improve check of compress-algorithm and compress-level
This commit is contained in:
parent
fbda56902b
commit
3e06d9fedc
@ -64,8 +64,7 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
|
||||
if (access(backup_wal_file_path, F_OK) != -1)
|
||||
elog(ERROR, "file '%s', already exists.", backup_wal_file_path);
|
||||
|
||||
push_wal_file(absolute_wal_file_path, backup_wal_file_path,
|
||||
compress_shortcut);
|
||||
push_wal_file(absolute_wal_file_path, backup_wal_file_path);
|
||||
elog(INFO, "pg_probackup archive-push completed successfully");
|
||||
|
||||
return 0;
|
||||
|
13
src/data.c
13
src/data.c
@ -750,7 +750,7 @@ copy_meta(const char *from_path, const char *to_path)
|
||||
* Copy WAL segment from pgdata to archive catalog with possible compression.
|
||||
*/
|
||||
void
|
||||
push_wal_file(const char *from_path, const char *to_path, bool is_compress)
|
||||
push_wal_file(const char *from_path, const char *to_path)
|
||||
{
|
||||
FILE *in = NULL;
|
||||
FILE *out;
|
||||
@ -770,7 +770,10 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress)
|
||||
|
||||
/* open backup file for write */
|
||||
#ifdef HAVE_LIBZ
|
||||
if (is_compress)
|
||||
if (compress_alg == PGLZ_COMPRESS)
|
||||
elog(ERROR, "pglz compression is not supported");
|
||||
|
||||
if (compress_alg == ZLIB_COMPRESS)
|
||||
{
|
||||
snprintf(gz_to_path, sizeof(gz_to_path), "%s.gz", to_path);
|
||||
gz_out = gzopen(gz_to_path, "wb");
|
||||
@ -803,7 +806,7 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress)
|
||||
if (read_len > 0)
|
||||
{
|
||||
#ifdef HAVE_LIBZ
|
||||
if (is_compress)
|
||||
if (compress_alg == ZLIB_COMPRESS)
|
||||
{
|
||||
if (gzwrite(gz_out, buf, read_len) != read_len)
|
||||
elog(ERROR, "Cannot write to compressed WAL segment \"%s\": %s",
|
||||
@ -823,10 +826,10 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress)
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
if (is_compress && gzclose(gz_out) != 0)
|
||||
if (compress_alg == ZLIB_COMPRESS && gzclose(gz_out) != 0)
|
||||
elog(ERROR, "Cannot close compressed WAL segment \"%s\": %s",
|
||||
gz_to_path, get_gz_error(gz_out));
|
||||
else if (!is_compress)
|
||||
else if (compress_alg != ZLIB_COMPRESS)
|
||||
#endif
|
||||
{
|
||||
if (fflush(out) != 0 ||
|
||||
|
@ -403,6 +403,9 @@ main(int argc, char *argv[])
|
||||
if (compress_level < 0 || compress_level > 9)
|
||||
elog(ERROR, "--compress-level value must be in the range from 0 to 9");
|
||||
|
||||
if (compress_level == 0)
|
||||
compress_alg = NOT_DEFINED_COMPRESS;
|
||||
|
||||
/* do actual operation */
|
||||
switch (backup_subcmd)
|
||||
{
|
||||
|
@ -427,8 +427,7 @@ extern void restore_data_file(const char *from_root, const char *to_root,
|
||||
pgFile *file, pgBackup *backup);
|
||||
extern bool copy_file(const char *from_root, const char *to_root,
|
||||
pgFile *file);
|
||||
extern void push_wal_file(const char *from_path, const char *to_path,
|
||||
bool is_compress);
|
||||
extern void push_wal_file(const char *from_path, const char *to_path);
|
||||
extern void get_wal_file(const char *from_path, const char *to_path);
|
||||
|
||||
extern bool calc_file_checksum(pgFile *file);
|
||||
|
Loading…
Reference in New Issue
Block a user