mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-02-09 14:33:17 +02:00
PGPRO-692: Do not compress .history and .backup files. Improve messages.
This commit is contained in:
parent
3e06d9fedc
commit
c5e425995d
@ -29,6 +29,7 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
|
|||||||
char current_dir[MAXPGPATH];
|
char current_dir[MAXPGPATH];
|
||||||
int64 system_id;
|
int64 system_id;
|
||||||
pgBackupConfig *config;
|
pgBackupConfig *config;
|
||||||
|
bool is_compress = false;
|
||||||
|
|
||||||
if (wal_file_name == NULL && wal_file_path == NULL)
|
if (wal_file_name == NULL && wal_file_path == NULL)
|
||||||
elog(ERROR, "required parameters are not specified: --wal-file-name %%f --wal-file-path %%p");
|
elog(ERROR, "required parameters are not specified: --wal-file-name %%f --wal-file-path %%p");
|
||||||
@ -64,7 +65,14 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
|
|||||||
if (access(backup_wal_file_path, F_OK) != -1)
|
if (access(backup_wal_file_path, F_OK) != -1)
|
||||||
elog(ERROR, "file '%s', already exists.", backup_wal_file_path);
|
elog(ERROR, "file '%s', already exists.", backup_wal_file_path);
|
||||||
|
|
||||||
push_wal_file(absolute_wal_file_path, backup_wal_file_path);
|
#ifdef HAVE_LIBZ
|
||||||
|
if (compress_alg == PGLZ_COMPRESS)
|
||||||
|
elog(ERROR, "pglz compression is not supported");
|
||||||
|
if (compress_alg == ZLIB_COMPRESS)
|
||||||
|
is_compress = IsXLogFileName(wal_file_name);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
push_wal_file(absolute_wal_file_path, backup_wal_file_path, is_compress);
|
||||||
elog(INFO, "pg_probackup archive-push completed successfully");
|
elog(INFO, "pg_probackup archive-push completed successfully");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
65
src/data.c
65
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.
|
* Copy WAL segment from pgdata to archive catalog with possible compression.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
push_wal_file(const char *from_path, const char *to_path)
|
push_wal_file(const char *from_path, const char *to_path, bool is_compress)
|
||||||
{
|
{
|
||||||
FILE *in = NULL;
|
FILE *in = NULL;
|
||||||
FILE *out;
|
FILE *out;
|
||||||
@ -765,20 +765,17 @@ push_wal_file(const char *from_path, const char *to_path)
|
|||||||
/* open file for read */
|
/* open file for read */
|
||||||
in = fopen(from_path, "r");
|
in = fopen(from_path, "r");
|
||||||
if (in == NULL)
|
if (in == NULL)
|
||||||
elog(ERROR, "Cannot open source WAL segment \"%s\": %s", from_path,
|
elog(ERROR, "Cannot open source WAL file \"%s\": %s", from_path,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
/* open backup file for write */
|
/* open backup file for write */
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
if (compress_alg == PGLZ_COMPRESS)
|
if (is_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);
|
snprintf(gz_to_path, sizeof(gz_to_path), "%s.gz", to_path);
|
||||||
gz_out = gzopen(gz_to_path, "wb");
|
gz_out = gzopen(gz_to_path, "wb");
|
||||||
if (gzsetparams(gz_out, compress_level, Z_DEFAULT_STRATEGY) != Z_OK)
|
if (gzsetparams(gz_out, compress_level, Z_DEFAULT_STRATEGY) != Z_OK)
|
||||||
elog(ERROR, "Cannot set compression level %d to segment \"%s\": %s",
|
elog(ERROR, "Cannot set compression level %d to file \"%s\": %s",
|
||||||
compress_level, gz_to_path, get_gz_error(gz_out));
|
compress_level, gz_to_path, get_gz_error(gz_out));
|
||||||
|
|
||||||
to_path_p = gz_to_path;
|
to_path_p = gz_to_path;
|
||||||
@ -788,7 +785,7 @@ push_wal_file(const char *from_path, const char *to_path)
|
|||||||
{
|
{
|
||||||
out = fopen(to_path, "w");
|
out = fopen(to_path, "w");
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
elog(ERROR, "Cannot open destination WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot open destination WAL file \"%s\": %s",
|
||||||
to_path, strerror(errno));
|
to_path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -800,23 +797,23 @@ push_wal_file(const char *from_path, const char *to_path)
|
|||||||
read_len = fread(buf, 1, sizeof(buf), in);
|
read_len = fread(buf, 1, sizeof(buf), in);
|
||||||
|
|
||||||
if (ferror(in))
|
if (ferror(in))
|
||||||
elog(ERROR, "Cannot read source WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot read source WAL file \"%s\": %s",
|
||||||
from_path, strerror(errno));
|
from_path, strerror(errno));
|
||||||
|
|
||||||
if (read_len > 0)
|
if (read_len > 0)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
if (compress_alg == ZLIB_COMPRESS)
|
if (is_compress)
|
||||||
{
|
{
|
||||||
if (gzwrite(gz_out, buf, read_len) != read_len)
|
if (gzwrite(gz_out, buf, read_len) != read_len)
|
||||||
elog(ERROR, "Cannot write to compressed WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot write to compressed WAL file \"%s\": %s",
|
||||||
gz_to_path, get_gz_error(gz_out));
|
gz_to_path, get_gz_error(gz_out));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (fwrite(buf, 1, read_len, out) != read_len)
|
if (fwrite(buf, 1, read_len, out) != read_len)
|
||||||
elog(ERROR, "Cannot write to WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot write to WAL file \"%s\": %s",
|
||||||
to_path, strerror(errno));
|
to_path, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -826,21 +823,25 @@ push_wal_file(const char *from_path, const char *to_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
if (compress_alg == ZLIB_COMPRESS && gzclose(gz_out) != 0)
|
if (is_compress)
|
||||||
elog(ERROR, "Cannot close compressed WAL segment \"%s\": %s",
|
{
|
||||||
gz_to_path, get_gz_error(gz_out));
|
if (gzclose(gz_out) != 0)
|
||||||
else if (compress_alg != ZLIB_COMPRESS)
|
elog(ERROR, "Cannot close compressed WAL file \"%s\": %s",
|
||||||
|
gz_to_path, get_gz_error(gz_out));
|
||||||
|
elog(INFO, "WAL file compressed to \"%s\"", gz_to_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (fflush(out) != 0 ||
|
if (fflush(out) != 0 ||
|
||||||
fsync(fileno(out)) != 0 ||
|
fsync(fileno(out)) != 0 ||
|
||||||
fclose(out))
|
fclose(out))
|
||||||
elog(ERROR, "Cannot write WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot write WAL file \"%s\": %s",
|
||||||
to_path, strerror(errno));
|
to_path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(in))
|
if (fclose(in))
|
||||||
elog(ERROR, "Cannot close source WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot close source WAL file \"%s\": %s",
|
||||||
from_path, strerror(errno));
|
from_path, strerror(errno));
|
||||||
|
|
||||||
/* update file permission. */
|
/* update file permission. */
|
||||||
@ -883,7 +884,7 @@ get_wal_file(const char *from_path, const char *to_path)
|
|||||||
}
|
}
|
||||||
/* Cannot open compressed file for some reason */
|
/* Cannot open compressed file for some reason */
|
||||||
else
|
else
|
||||||
elog(ERROR, "Cannot open compressed WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot open compressed WAL file \"%s\": %s",
|
||||||
gz_from_path, strerror(errno));
|
gz_from_path, strerror(errno));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -895,14 +896,14 @@ get_wal_file(const char *from_path, const char *to_path)
|
|||||||
#endif
|
#endif
|
||||||
/* Didn't find compressed file */
|
/* Didn't find compressed file */
|
||||||
if (!is_decompress)
|
if (!is_decompress)
|
||||||
elog(ERROR, "Cannot open source WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot open source WAL file \"%s\": %s",
|
||||||
from_path, strerror(errno));
|
from_path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open backup file for write */
|
/* open backup file for write */
|
||||||
out = fopen(to_path, "w");
|
out = fopen(to_path, "w");
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
elog(ERROR, "Cannot open destination WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot open destination WAL file \"%s\": %s",
|
||||||
to_path, strerror(errno));
|
to_path, strerror(errno));
|
||||||
|
|
||||||
/* copy content */
|
/* copy content */
|
||||||
@ -915,7 +916,7 @@ get_wal_file(const char *from_path, const char *to_path)
|
|||||||
{
|
{
|
||||||
read_len = gzread(gz_in, buf, sizeof(buf));
|
read_len = gzread(gz_in, buf, sizeof(buf));
|
||||||
if (read_len != sizeof(buf) && !gzeof(gz_in))
|
if (read_len != sizeof(buf) && !gzeof(gz_in))
|
||||||
elog(ERROR, "Cannot read compressed WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot read compressed WAL file \"%s\": %s",
|
||||||
gz_from_path, get_gz_error(gz_in));
|
gz_from_path, get_gz_error(gz_in));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -923,14 +924,14 @@ get_wal_file(const char *from_path, const char *to_path)
|
|||||||
{
|
{
|
||||||
read_len = fread(buf, 1, sizeof(buf), in);
|
read_len = fread(buf, 1, sizeof(buf), in);
|
||||||
if (ferror(in))
|
if (ferror(in))
|
||||||
elog(ERROR, "Cannot read source WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot read source WAL file \"%s\": %s",
|
||||||
from_path, strerror(errno));
|
from_path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_len > 0)
|
if (read_len > 0)
|
||||||
{
|
{
|
||||||
if (fwrite(buf, 1, read_len, out) != read_len)
|
if (fwrite(buf, 1, read_len, out) != read_len)
|
||||||
elog(ERROR, "Cannot write to WAL segment \"%s\": %s", to_path,
|
elog(ERROR, "Cannot write to WAL file \"%s\": %s", to_path,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -952,18 +953,22 @@ get_wal_file(const char *from_path, const char *to_path)
|
|||||||
if (fflush(out) != 0 ||
|
if (fflush(out) != 0 ||
|
||||||
fsync(fileno(out)) != 0 ||
|
fsync(fileno(out)) != 0 ||
|
||||||
fclose(out))
|
fclose(out))
|
||||||
elog(ERROR, "Cannot write WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot write WAL file \"%s\": %s",
|
||||||
to_path, strerror(errno));
|
to_path, strerror(errno));
|
||||||
|
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
if (is_decompress && gzclose(gz_in) != 0)
|
if (is_decompress)
|
||||||
elog(ERROR, "Cannot close compressed WAL segment \"%s\": %s",
|
{
|
||||||
gz_from_path, get_gz_error(gz_in));
|
if (gzclose(gz_in) != 0)
|
||||||
else if (!is_decompress)
|
elog(ERROR, "Cannot close compressed WAL file \"%s\": %s",
|
||||||
|
gz_from_path, get_gz_error(gz_in));
|
||||||
|
elog(INFO, "WAL file decompressed from \"%s\"", gz_from_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (fclose(in))
|
if (fclose(in))
|
||||||
elog(ERROR, "Cannot close source WAL segment \"%s\": %s",
|
elog(ERROR, "Cannot close source WAL file \"%s\": %s",
|
||||||
from_path, strerror(errno));
|
from_path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,8 @@ extern void restore_data_file(const char *from_root, const char *to_root,
|
|||||||
pgFile *file, pgBackup *backup);
|
pgFile *file, pgBackup *backup);
|
||||||
extern bool copy_file(const char *from_root, const char *to_root,
|
extern bool copy_file(const char *from_root, const char *to_root,
|
||||||
pgFile *file);
|
pgFile *file);
|
||||||
extern void push_wal_file(const char *from_path, const char *to_path);
|
extern void push_wal_file(const char *from_path, const char *to_path,
|
||||||
|
bool is_compress);
|
||||||
extern void get_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);
|
extern bool calc_file_checksum(pgFile *file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user