]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/postgres/files/backup_server/postgres-make-base-backups
move pg full backups to pull model
[dsa-puppet.git] / modules / postgres / files / backup_server / postgres-make-base-backups
1 #!/bin/bash
2
3 # run a bunch of full postgresql backups
4
5
6 # Copyright 2014 Peter Palfrader
7 #
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:
15 #
16 # The above copyright notice and this permission notice shall be
17 # included in all copies or substantial portions of the Software.
18 #
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.
26
27
28 set -e
29 set -u
30
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"
35         exit 1
36 fi
37
38 if [ -t 0 ]; then
39         console="--progress --verbose"
40 else
41         console=""
42 fi
43
44 export PGSSLMODE=verify-full
45 export PGSSLROOTCERT=/etc/ssl/debian/certs/ca.crt
46
47 date=$(date "+%Y%m%d-%H%M%S")
48
49 while read host port username  cluster version; do
50         [ "${host#\#}" = "$host" ] || continue
51
52         label="$date-$host-$cluster-$version-backup"
53         [ -t 0 ] && echo "Doing $host:$port $version/$cluster: $label"
54
55         target="$cluster.BASE.$label.tar.gz"
56         tmp=$(tempfile -d "$ROOTDIR" -p "BASE-$host:$port-" -s ".tar.gz")
57         trap "rm -f '$tmp'" EXIT
58
59         /usr/lib/postgresql/"$version"/bin/pg_basebackup --format=tar --pgdata=- --label="$label" --host="$host" --port="$port" --username="$username" --no-password $console | pigz > "$tmp"
60         mv "$tmp" "$ROOTDIR/${host%%.*}/$target"
61 done << EOF
62 chopin.debian.org       5432    debian-backup           dak             9.1
63 bmdb1.debian.org        5435    debian-backup           main            9.1
64 bmdb1.debian.org        5436    debian-backup           wanna-build     9.1
65 danzi.debian.org        5433    debian-backup           main            9.1
66 franck.debian.org       5433    debian-backup           dak             9.1
67 sibelius.debian.org     5433    debian-backup           snapshot        9.1
68 EOF