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