diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:02:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:02:19 +0000 |
commit | e308bcff5a610d6a3bbe33b3769f03f6d4533b16 (patch) | |
tree | 6a8ed4eb26cd55f3a24165bc1d9b9a1f0ab62e8c /pg_getwal | |
parent | Initial commit. (diff) | |
download | postgresql-common-e308bcff5a610d6a3bbe33b3769f03f6d4533b16.tar.xz postgresql-common-e308bcff5a610d6a3bbe33b3769f03f6d4533b16.zip |
Adding upstream version 248.upstream/248upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | pg_getwal | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/pg_getwal b/pg_getwal new file mode 100755 index 0000000..8e64e87 --- /dev/null +++ b/pg_getwal @@ -0,0 +1,96 @@ +#!/bin/sh + +# retrieve a WAL file from a pg_receivewal archive +# +# Copyright (C) 2021-2022 Christoph Berg <myon@debian.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +set -eu + +binroot="/usr/lib/postgresql/" +#redhat# binroot="/usr/pgsql-" + +if [ -z "${2:-}" ]; then + echo "Syntax: $0 /path/to/wal/%f %p" >&2 + exit 1 +fi + +file="$1" +path="$2" + +# sanity-check the first argument +waldir="$(dirname $file)" +if ! [ -d "$waldir" ]; then + echo "$0: $waldir is not a directory" >&2 + exit 129 +fi + +if [ -f "$file.gz" ]; then + gunzip < "$file.gz" > "$path" || exit 129 + +elif [ -f "$file.lz4" ]; then + unlz4 < "$file.lz4" > "$path" || exit 129 + +elif [ -f "$file" ]; then + cp "$file" "$path" || exit 129 + +elif [ -f "$file.gz.partial" ] || [ -f "$file.lz4.partial" ]; then + if [ -s "$file.gz.partial" ]; then + gunzip < "$file.gz.partial" > "$path" || exit 129 + elif [ -s "$file.lz4.partial" ]; then + unlz4 < "$file.lz4.partial" > "$path" || exit 129 + else + # .gz.partial starts completely empty, gunzip doesn't like that + touch "$path" || exit 129 + fi + + # expand file to original size + version=$(cat PG_VERSION) || exit 129 + wal_file_size=$(LC_ALL=C "$binroot$version/bin/pg_controldata" . | awk '/^Bytes per WAL segment:/ { print $5 }') || exit 129 + [ "$wal_file_size" -gt 0 ] || exit 129 + truncate --size="$wal_file_size" "$path" || exit 129 + +elif [ -f "$file.partial" ]; then + cp "$file.partial" "$path" || exit 129 + +else + # file not found, exit silently in order not to spam the server log with errors + exit 1 +fi + +exit 0 + +: <<=cut + +=head1 NAME + +pg_getwal - retrieve a WAL file from a pg_receivewal archive + +=head1 SYNOPSIS + +B<pg_getwal> I</path/to/wal/%f> I<%p> + +=head1 DESCRIPTION + +B<pg_getwal> retrieves and decompresses files from a WAL archive maintained by +B<pg_receivewal> and B<pg_backupcluster>. It is put into PostgreSQL's +B<restore_command> by B<pg_restorecluster>. + +=head1 SEE ALSO + +L<pg_restorecluster(1)>, L<pg_backupcluster(1)>. + +=head1 AUTHOR + +Christoph Berg L<E<lt>myon@debian.orgE<gt>> + +=cut |