1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-02-07 14:18:17 +02:00

Simplify code related to HAVE_DATABASE, HAVE_ARCLOG, TOTAL_READ_SIZE

Those macros were mainly used in code paths where they didn't make that
much sense, complicating heavily the code. Correct at the same time some
code comments.
This commit is contained in:
Michael Paquier 2013-12-16 00:30:49 +09:00
parent 96cfb3eb13
commit 05ce188607
6 changed files with 94 additions and 67 deletions

View File

@ -660,28 +660,35 @@ do_backup(pgBackupOption bkupopt)
/* PGDATA and BACKUP_MODE are always required */ /* PGDATA and BACKUP_MODE are always required */
if (pgdata == NULL) if (pgdata == NULL)
elog(ERROR_ARGS, _("required parameter not specified: PGDATA (-D, --pgdata)")); elog(ERROR_ARGS, _("Required parameter not specified: PGDATA "
"(-D, --pgdata)"));
/* A backup mode is needed */
if (current.backup_mode == BACKUP_MODE_INVALID) if (current.backup_mode == BACKUP_MODE_INVALID)
elog(ERROR_ARGS, _("required parameter not specified: BACKUP_MODE (-b, --backup-mode)")); elog(ERROR_ARGS, _("Required parameter not specified: BACKUP_MODE "
"(-b, --backup-mode)"));
/* ARCLOG_PATH is requried only when backup archive WAL */ /* ARCLOG_PATH is required for all the modes */
if (HAVE_ARCLOG(&current) && arclog_path == NULL) if (arclog_path == NULL)
elog(ERROR_ARGS, _("required parameter not specified: ARCLOG_PATH (-A, --arclog-path)")); elog(ERROR_ARGS,
_("Required parameter not specified: ARCLOG_PATH "
"(-A, --arclog-path)"));
/* SRVLOG_PATH is required only when backup serverlog */ /* SRVLOG_PATH is required only when backup serverlog */
if (current.with_serverlog && srvlog_path == NULL) if (current.with_serverlog && srvlog_path == NULL)
elog(ERROR_ARGS, _("required parameter not specified: SRVLOG_PATH (-S, --srvlog-path)")); elog(ERROR_ARGS, _("required parameter not specified: SRVLOG_PATH "
"(-S, --srvlog-path)"));
#ifndef HAVE_LIBZ #ifndef HAVE_LIBZ
if (current.compress_data) if (current.compress_data)
{ {
elog(WARNING, _("requested compression not available in this: installation -- archive will be uncompressed")); elog(WARNING, _("requested compression not available in this "
"installation. Archive will not be compressed"));
current.compress_data = false; current.compress_data = false;
} }
#endif #endif
/* confirm data block size and xlog block size are compatible */ /* Confirm data block size and xlog block size are compatible */
check_server_version(); check_server_version();
/* setup cleanup callback function */ /* setup cleanup callback function */
@ -758,21 +765,35 @@ do_backup(pgBackupOption bkupopt)
if (!check) if (!check)
pgBackupWriteIni(&current); pgBackupWriteIni(&current);
/* Calculate the total data read */
if (verbose) if (verbose)
{ {
if (TOTAL_READ_SIZE(&current) == 0) int64 total_read = 0;
/* WAL archives */
total_read += current.read_arclog_bytes;
/* Database data */
if (current.backup_mode == BACKUP_MODE_FULL ||
current.backup_mode == BACKUP_MODE_INCREMENTAL)
total_read += current.read_arclog_bytes;
/* Server logs */
if (current.with_serverlog)
total_read += current.read_srvlog_bytes;
if (total_read == 0)
printf(_("nothing to backup\n")); printf(_("nothing to backup\n"));
else else
printf(_("all backup completed(read: " INT64_FORMAT " write: " printf(_("all backup completed(read: " INT64_FORMAT " write: "
INT64_FORMAT ")\n"), INT64_FORMAT ")\n"),
TOTAL_READ_SIZE(&current), current.write_bytes); total_read, current.write_bytes);
printf(_("========================================\n")); printf(_("========================================\n"));
} }
/* /*
* Delete old files (archived WAL and serverlog) after update of status. * Delete old files (archived WAL and serverlog) after update of status.
*/ */
if (HAVE_ARCLOG(&current))
delete_old_files(arclog_path, files_arclog, keep_arclog_files, delete_old_files(arclog_path, files_arclog, keep_arclog_files,
keep_arclog_days, true); keep_arclog_days, true);
if (current.with_serverlog) if (current.with_serverlog)

View File

@ -254,8 +254,13 @@ catalog_get_last_data_backup(parray *backup_list)
{ {
backup = (pgBackup *) parray_get(backup_list, i); backup = (pgBackup *) parray_get(backup_list, i);
/* we need completed database backup */ /*
if (backup->status == BACKUP_STATUS_OK && HAVE_DATABASE(backup)) * We need completed database backup in the case of a full or
* incremental backup.
*/
if (backup->status == BACKUP_STATUS_OK &&
(backup->backup_mode == BACKUP_MODE_INCREMENTAL ||
backup->backup_mode == BACKUP_MODE_FULL))
return backup; return backup;
} }
@ -277,7 +282,7 @@ catalog_get_last_arclog_backup(parray *backup_list)
backup = (pgBackup *) parray_get(backup_list, i); backup = (pgBackup *) parray_get(backup_list, i);
/* we need completed archived WAL backup */ /* we need completed archived WAL backup */
if (backup->status == BACKUP_STATUS_OK && HAVE_ARCLOG(backup)) if (backup->status == BACKUP_STATUS_OK)
return backup; return backup;
} }

View File

@ -176,13 +176,6 @@ typedef struct pgBackupOption
#define KEEP_INFINITE (INT_MAX) #define KEEP_INFINITE (INT_MAX)
#define BYTES_INVALID (-1) #define BYTES_INVALID (-1)
#define HAVE_DATABASE(backup) ((backup)->backup_mode >= BACKUP_MODE_INCREMENTAL)
#define HAVE_ARCLOG(backup) ((backup)->backup_mode >= BACKUP_MODE_ARCHIVE)
#define TOTAL_READ_SIZE(backup) \
((HAVE_DATABASE((backup)) ? (backup)->read_data_bytes : 0) + \
(HAVE_ARCLOG((backup)) ? (backup)->read_arclog_bytes : 0) + \
((backup)->with_serverlog ? (backup)->read_srvlog_bytes : 0))
typedef struct pgTimeLine typedef struct pgTimeLine
{ {
TimeLineID tli; TimeLineID tli;
@ -265,7 +258,9 @@ extern char *slurpFile(const char *datadir,
/* in validate.c */ /* in validate.c */
extern int do_validate(pgBackupRange *range); extern int do_validate(pgBackupRange *range);
extern void pgBackupValidate(pgBackup *backup, bool size_only, bool for_get_timeline, bool with_database); extern void pgBackupValidate(pgBackup *backup,
bool size_only,
bool for_get_timeline);
/* in catalog.c */ /* in catalog.c */
extern pgBackup *catalog_get_backup(time_t timestamp); extern pgBackup *catalog_get_backup(time_t timestamp);

View File

@ -164,14 +164,14 @@ do_restore(const char *target_time,
#ifndef HAVE_LIBZ #ifndef HAVE_LIBZ
/* Make sure we won't need decompression we haven't got */ /* Make sure we won't need decompression we haven't got */
if (base_backup->compress_data && if (base_backup->compress_data)
(HAVE_DATABASE(base_backup) || HAVE_ARCLOG(base_backup)))
{
elog(ERROR_SYSTEM, elog(ERROR_SYSTEM,
_("can't restore from compressed backup (compression not supported in this installation)")); _("can't restore from compressed backup (compression "
} "not supported in this installation)"));
#endif #endif
if (satisfy_timeline(timelines, base_backup) && satisfy_recovery_target(base_backup, rt)) if (satisfy_timeline(timelines, base_backup) &&
satisfy_recovery_target(base_backup, rt))
goto base_backup_found; goto base_backup_found;
} }
/* no full backup found, can't restore */ /* no full backup found, can't restore */
@ -238,9 +238,6 @@ base_backup_found:
if (backup->status != BACKUP_STATUS_OK) if (backup->status != BACKUP_STATUS_OK)
continue; continue;
if (!HAVE_ARCLOG(backup))
continue;
/* care timeline junction */ /* care timeline junction */
if (!satisfy_timeline(timelines, backup)) if (!satisfy_timeline(timelines, backup))
continue; continue;
@ -333,7 +330,7 @@ restore_database(pgBackup *backup)
* Validate backup files with its size, because load of CRC calculation is * Validate backup files with its size, because load of CRC calculation is
* not right. * not right.
*/ */
pgBackupValidate(backup, true, false, true); pgBackupValidate(backup, true, false);
/* make direcotries and symbolic links */ /* make direcotries and symbolic links */
pgBackupGetPath(backup, path, lengthof(path), MKDIRS_SH_FILE); pgBackupGetPath(backup, path, lengthof(path), MKDIRS_SH_FILE);
@ -497,7 +494,7 @@ restore_archive_logs(pgBackup *backup, bool is_hard_copy)
* Validate backup files with its size, because load of CRC calculation is * Validate backup files with its size, because load of CRC calculation is
* not light. * not light.
*/ */
pgBackupValidate(backup, true, false, false); pgBackupValidate(backup, true, false);
pgBackupGetPath(backup, list_path, lengthof(list_path), ARCLOG_FILE_LIST); pgBackupGetPath(backup, list_path, lengthof(list_path), ARCLOG_FILE_LIST);
pgBackupGetPath(backup, base_path, lengthof(list_path), ARCLOG_DIR); pgBackupGetPath(backup, base_path, lengthof(list_path), ARCLOG_DIR);
@ -851,11 +848,11 @@ static bool
satisfy_recovery_target(const pgBackup *backup, const pgRecoveryTarget *rt) satisfy_recovery_target(const pgBackup *backup, const pgRecoveryTarget *rt)
{ {
if (rt->xid_specified) if (rt->xid_specified)
return backup->recovery_xid <= rt->recovery_target_xid); return backup->recovery_xid <= rt->recovery_target_xid;
if (rt->time_specified) if (rt->time_specified)
return backup->recovery_time <= rt->recovery_target_time); return backup->recovery_time <= rt->recovery_target_time;
else
return true; return true;
} }
@ -948,7 +945,7 @@ get_fullbackup_timeline(parray *backups, const pgRecoveryTarget *rt)
* calculation is not right. * calculation is not right.
*/ */
if (base_backup->status == BACKUP_STATUS_DONE) if (base_backup->status == BACKUP_STATUS_DONE)
pgBackupValidate(base_backup, true, true, false); pgBackupValidate(base_backup, true, true);
if(!satisfy_recovery_target(base_backup, rt)) if(!satisfy_recovery_target(base_backup, rt))
continue; continue;

5
show.c
View File

@ -189,13 +189,12 @@ show_backup_list(FILE *out, parray *backup_list, bool show_all)
snprintf(duration, lengthof(duration), "%lum", snprintf(duration, lengthof(duration), "%lum",
(backup->end_time - backup->start_time) / 60); (backup->end_time - backup->start_time) / 60);
/* "Full" is only for full backup */ /* "Full" is only for full backup */
if (backup->backup_mode >= BACKUP_MODE_FULL) if (backup->backup_mode == BACKUP_MODE_FULL)
pretty_size(backup->total_data_bytes, total_data_bytes_str, pretty_size(backup->total_data_bytes, total_data_bytes_str,
lengthof(total_data_bytes_str)); lengthof(total_data_bytes_str));
else if (backup->backup_mode >= BACKUP_MODE_INCREMENTAL) if (backup->backup_mode == BACKUP_MODE_INCREMENTAL)
pretty_size(backup->read_data_bytes, read_data_bytes_str, pretty_size(backup->read_data_bytes, read_data_bytes_str,
lengthof(read_data_bytes_str)); lengthof(read_data_bytes_str));
if (HAVE_ARCLOG(backup))
pretty_size(backup->read_arclog_bytes, read_arclog_bytes_str, pretty_size(backup->read_arclog_bytes, read_arclog_bytes_str,
lengthof(read_arclog_bytes_str)); lengthof(read_arclog_bytes_str));
if (backup->with_serverlog) if (backup->with_serverlog)

View File

@ -51,7 +51,7 @@ do_validate(pgBackupRange *range)
continue; continue;
/* validate with CRC value and update status to OK */ /* validate with CRC value and update status to OK */
pgBackupValidate(backup, false, false, (HAVE_DATABASE(backup))); pgBackupValidate(backup, false, false);
} }
/* cleanup */ /* cleanup */
@ -67,7 +67,9 @@ do_validate(pgBackupRange *range)
* Validate each files in the backup with its size. * Validate each files in the backup with its size.
*/ */
void void
pgBackupValidate(pgBackup *backup, bool size_only, bool for_get_timeline, bool with_database) pgBackupValidate(pgBackup *backup,
bool size_only,
bool for_get_timeline)
{ {
char timestamp[100]; char timestamp[100];
char base_path[MAXPGPATH]; char base_path[MAXPGPATH];
@ -76,19 +78,27 @@ pgBackupValidate(pgBackup *backup, bool size_only, bool for_get_timeline, bool w
bool corrupted = false; bool corrupted = false;
time2iso(timestamp, lengthof(timestamp), backup->start_time); time2iso(timestamp, lengthof(timestamp), backup->start_time);
if(!for_get_timeline){ if (!for_get_timeline)
if (with_database) {
elog(INFO, "validate: %s backup and archive log files by %s", timestamp, (size_only ? "SIZE" : "CRC")); if (backup->backup_mode == BACKUP_MODE_FULL ||
else{ backup->backup_mode == BACKUP_MODE_INCREMENTAL)
elog(INFO, "validate: %s backup and archive log files by %s",
timestamp, (size_only ? "SIZE" : "CRC"));
else
{
if (backup->backup_mode == BACKUP_MODE_ARCHIVE) if (backup->backup_mode == BACKUP_MODE_ARCHIVE)
elog(INFO, "validate: %s archive log files by %s", timestamp, (size_only ? "SIZE" : "CRC")); elog(INFO, "validate: %s archive log files by %s",
timestamp, (size_only ? "SIZE" : "CRC"));
else if (backup->with_serverlog) else if (backup->with_serverlog)
elog(INFO, "validate: %s server log files by %s", timestamp, (size_only ? "SIZE" : "CRC")); elog(INFO, "validate: %s server log files by %s",
timestamp, (size_only ? "SIZE" : "CRC"));
} }
} }
if(!check){ if (!check)
if (HAVE_DATABASE(backup)) {
if (backup->backup_mode == BACKUP_MODE_FULL ||
backup->backup_mode == BACKUP_MODE_INCREMENTAL)
{ {
elog(LOG, "database files..."); elog(LOG, "database files...");
pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR); pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR);
@ -100,8 +110,8 @@ pgBackupValidate(pgBackup *backup, bool size_only, bool for_get_timeline, bool w
parray_walk(files, pgFileFree); parray_walk(files, pgFileFree);
parray_free(files); parray_free(files);
} }
if (HAVE_ARCLOG(backup))
{ /* WAL archives are present for all modes */
elog(LOG, "archive WAL files..."); elog(LOG, "archive WAL files...");
pgBackupGetPath(backup, base_path, lengthof(base_path), ARCLOG_DIR); pgBackupGetPath(backup, base_path, lengthof(base_path), ARCLOG_DIR);
pgBackupGetPath(backup, path, lengthof(path), ARCLOG_FILE_LIST); pgBackupGetPath(backup, path, lengthof(path), ARCLOG_FILE_LIST);
@ -110,7 +120,7 @@ pgBackupValidate(pgBackup *backup, bool size_only, bool for_get_timeline, bool w
corrupted = true; corrupted = true;
parray_walk(files, pgFileFree); parray_walk(files, pgFileFree);
parray_free(files); parray_free(files);
}
if (backup->with_serverlog) if (backup->with_serverlog)
{ {
elog(LOG, "server log files..."); elog(LOG, "server log files...");