3 # run a bunch of full postgresql backups
7 # Copyright 2014 Peter Palfrader
9 # Permission is hereby granted, free of charge, to any person obtaining
10 # a copy of this software and associated documentation files (the
11 # "Software"), to deal in the Software without restriction, including
12 # without limitation the rights to use, copy, modify, merge, publish,
13 # distribute, sublicense, and/or sell copies of the Software, and to
14 # permit persons to whom the Software is furnished to do so, subject to
15 # the following conditions:
17 # The above copyright notice and this permission notice shall be
18 # included in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 CONFFILE=/etc/nagios/dsa-check-backuppg.conf
33 ROOTDIR=$(perl -MYAML -e "print YAML::LoadFile('$CONFFILE')->{'rootdir'}")
34 if [ -z "$ROOTDIR" ]; then
35 echo >&2 "Could not learn rootdir from $CONFFILE"
45 if [ "$verbose" -gt 0 ]; then
46 console="--progress --verbose"
51 if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
52 echo "Usage: $0 [<host>:<port>]"
56 if [ "$#" -gt 0 ]; then
63 export PGSSLMODE=verify-full
64 export PGSSLROOTCERT=/etc/ssl/debian/certs/ca.crt
66 date=$(date "+%Y%m%d-%H%M%S")
67 thishost=$(hostname -f)
69 while read host port username cluster version; do
70 [ "${host#\#}" = "$host" ] || continue
71 [ -z "$host" ] && continue
73 if [ -n "$forcehostport" ] && [ "$forcehostport" != "$host:$port" ]; then
74 [ "$verbose" -gt 0 ] && echo "Skipping $host:$port $version/$cluster."
78 label="$thishost-$date-$host-$cluster-$version-backup"
79 [ "$verbose" -gt 0 ] && echo "Doing $host:$port $version/$cluster: $label"
81 target="$cluster.BASE.$label.tar.gz"
82 tmp=$(tempfile -d "$ROOTDIR" -p "BASE-$host:$port-" -s ".tar.gz")
83 trap "rm -f '$tmp'" EXIT
85 /usr/lib/postgresql/"$version"/bin/pg_basebackup --format=tar --pgdata=- --label="$label" --host="$host" --port="$port" --username="$username" --no-password $console | pigz > "$tmp"
86 if ! [ "${PIPESTATUS[0]}" -eq 0 ]; then
87 echo >&2 "pg_basebackup failed with exit code ${PIPESTATUS[0]}"
90 mv "$tmp" "$ROOTDIR/${host%%.*}/$target"
92 seger.debian.org 5432 debian-backup dak 9.6
93 bmdb1.debian.org 5435 debian-backup main 9.6
94 bmdb1.debian.org 5436 debian-backup wannabuild 9.6
95 bmdb1.debian.org 5440 debian-backup debsources 9.6
96 fasolo.debian.org 5433 debian-backup dak 9.6
97 sibelius.debian.org 5433 debian-backup snapshot 9.4
98 <%- if @hostname != "backuphost" -%>
99 moszumanska.debian.org 5432 debian-backup main 9.1
102 # puppet notice: this is just a partial file. The tail EOF comes
103 # from a different concat fragment