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"
43 if [ "$verbose" -gt 0 ]; then
44 console="--progress --verbose"
49 export PGSSLMODE=verify-full
50 export PGSSLROOTCERT=/etc/ssl/debian/certs/ca.crt
52 date=$(date "+%Y%m%d-%H%M%S")
54 while read host port username cluster version; do
55 [ "${host#\#}" = "$host" ] || continue
57 label="$date-$host-$cluster-$version-backup"
58 [ "$verbose" -gt 0 ] && echo "Doing $host:$port $version/$cluster: $label"
60 target="$cluster.BASE.$label.tar.gz"
61 tmp=$(tempfile -d "$ROOTDIR" -p "BASE-$host:$port-" -s ".tar.gz")
62 trap "rm -f '$tmp'" EXIT
64 /usr/lib/postgresql/"$version"/bin/pg_basebackup --format=tar --pgdata=- --label="$label" --host="$host" --port="$port" --username="$username" --no-password $console | pigz > "$tmp"
65 mv "$tmp" "$ROOTDIR/${host%%.*}/$target"
67 chopin.debian.org 5432 debian-backup dak 9.1
68 bmdb1.debian.org 5435 debian-backup main 9.1
69 bmdb1.debian.org 5436 debian-backup wanna-build 9.1
70 danzi.debian.org 5433 debian-backup main 9.1
71 franck.debian.org 5433 debian-backup dak 9.1
72 sibelius.debian.org 5433 debian-backup snapshot 9.1