Skip to content

Commit

Permalink
Check for each backup its needed archived WALs
Browse files Browse the repository at this point in the history
  • Loading branch information
pgstef committed Nov 14, 2019
1 parent 2310866 commit 5538abe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

2019-xx-xx v1.6:

- Check for each backup its needed archived WALs based on wal start/stop
information given by the pgBackRest "info" command.
- Return WARNING instead of CRITICAL in case of missing archived WAL prior
to latest backup, regardless its type.
- Add ignore-archived-before argument to ignore the archived WALs before the
Expand Down
26 changes: 24 additions & 2 deletions check_pgbackrest
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ sub check_wal_archives {
my $max_wal = $backups_info->{'archive'}[0]->{'max'};

# Get all the WAL archives and history files
dprint("Get all the WAL archives and history files...\n");
my ($filelist_ref, $branch_wals_ref) = &get_archived_wal_list($min_wal, $max_wal, \%args);
my @filelist;
@filelist = @{ $filelist_ref } if $filelist_ref;
Expand Down Expand Up @@ -849,6 +850,7 @@ sub check_wal_archives {
my $seg_per_wal = get_size($walsize) / get_size($wal_segsize); #Only for PG >= 9.3
my $dbver=($backups_info->{'db'}[0]->{'version'}+0)*10;
$seg_per_wal-- if $dbver <= 92;
dprint("Get all the needed wal archives...\n");
my @needed_wal_archives_list=&generate_needed_wal_archives_list($min_wal, $max_wal, \@branch_wals, $seg_per_wal);

# Get the latest backup info
Expand All @@ -857,17 +859,37 @@ sub check_wal_archives {
push @human_only_longmsg, "latest_bck_archive_start=".$latest_bck_archive_start;
push @human_only_longmsg, "latest_bck_type=".$latest_bck->{'type'};

my @warn_missing_file_msg;
my @crit_missing_file_msg;
# Go through needed wal list and check if it exists in the file list
foreach my $needed_wal (@needed_wal_archives_list) {
unless (grep /$needed_wal/, @filelist_simplified) {
if($needed_wal lt $latest_bck_archive_start) {
push @warn_msg => "wrong sequence or missing file @ '$needed_wal'";
push @warn_missing_file_msg => "wrong sequence or missing file @ '$needed_wal'";
}else{
push @crit_msg => "wrong sequence or missing file @ '$needed_wal'";
push @crit_missing_file_msg => "wrong sequence or missing file @ '$needed_wal'";
}
}
}

# Go through each backup to check their needed wal archives
foreach my $line (@{$backups_info->{'backup'}}){
dprint("Get all the needed wal archives for ".$line->{'label'}."...\n");
foreach my $needed_wal (&generate_needed_wal_archives_list($line->{'archive'}->{'start'}, $line->{'archive'}->{'stop'}, \@branch_wals, $seg_per_wal)) {
unless (grep /$needed_wal/, @filelist_simplified) {
push @crit_missing_file_msg => "wrong sequence or missing file @ '$needed_wal'";
}
}
}

# Generate @warn_msg and @crit_msg with missing files (sorted and unique messages)
my @unique_warn_missing_file_msg = do { my %seen; grep { !$seen{$_}++ } @warn_missing_file_msg };
push @warn_msg, sort @unique_warn_missing_file_msg;

push @crit_missing_file_msg, @warn_missing_file_msg if @warn_missing_file_msg and @crit_missing_file_msg;
my @unique_crit_missing_file_msg = do { my %seen; grep { !$seen{$_}++ } @crit_missing_file_msg };
push @crit_msg, sort @unique_crit_missing_file_msg;

}else{
push @crit_msg, $backups_info->{'status'}->{'message'};
}
Expand Down

0 comments on commit 5538abe

Please sign in to comment.