From: Peter Palfrader Date: Sat, 28 Sep 2019 18:25:07 +0000 (+0200) Subject: Move files for pg-backup-file from roles to postgres module X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=e9e6c1abe830ad5d653c9afd237f437fb07ee3ed;hp=4a7616f94fa2156a005712132a02345049d60a67;p=mirror%2Fdsa-puppet.git Move files for pg-backup-file from roles to postgres module --- diff --git a/modules/postgres/files/backup_source/pg-backup-file b/modules/postgres/files/backup_source/pg-backup-file new file mode 100755 index 000000000..9a432e56b --- /dev/null +++ b/modules/postgres/files/backup_source/pg-backup-file @@ -0,0 +1,81 @@ +#!/bin/bash + +# Copyright (c) 2010, 2011, 2013, 2014 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# Archive a postgresql file (WAL or BASE) to the archive server $backuphost +# can be set in /etc/dsa/pg-backup-file.conf + +set -u + +backuphost=debbackup@storace +myhost="`hostname`" +self="`basename "$0"`[$$]" + +if [ "$#" != 3 ] ; then + echo >&2 "Usage: $self " + exit 1 +fi + +ssh_options="" +! [ -e /etc/dsa/pg-backup-file.conf ] || . /etc/dsa/pg-backup-file.conf + +cluster="$1" +what="$2" +file="$3" + +info() { + logger -p daemon.info -t "$self" "$1" +} + +croak() { + logger -s -p daemon.warn -t "$self" "$1" + exit 1 +} + +if ! [ -e "$file" ] ; then + croak "file $file does not exist" +fi + +size="`stat -c '%s' "$file"`" +checksum="" +bn="`basename "$file"`" +targetname="$cluster.$what.$bn" +logtuple_start="($myhost,$targetname,$size" +failures="" + +for target in $backuphost; do + if [ "${target#/}" != "$target" ]; then + info "Archiving to $target: ($targetname,$size)" + cp "$file" "$target/$myhost-$targetname" + else + [ -n "$checksum" ] || checksum="`sha512sum "$file" | awk '{print $1}'`" + info "Archiving to $target: ($myhost,$targetname,$size,$checksum)" + + ssh -C "$target" $ssh_options -o BatchMode=yes -o ServerAliveInterval=90 $myhost store-file pg "$targetname" "$size" "$checksum" < "$file" + if [ "$?" != 0 ]; then + failures="$failures $logtuple_start,$checksum,$target)" + fi + fi +done +if [ "$failures" != "" ]; then + croak "remote store for$failures failed." +fi diff --git a/modules/postgres/manifests/backup_source.pp b/modules/postgres/manifests/backup_source.pp index b406d0dbe..e642ca732 100644 --- a/modules/postgres/manifests/backup_source.pp +++ b/modules/postgres/manifests/backup_source.pp @@ -4,15 +4,16 @@ class postgres::backup_source { file { '/usr/local/bin/pg-backup-file': mode => '0555', - source => 'puppet:///modules/roles/postgresql_server/pg-backup-file', + source => 'puppet:///modules/postgres/backup_sources/pg-backup-file', } + file { '/etc/dsa/pg-backup-file.conf': + content => template('postgres/backup_sources/pg-backup-file.conf.erb'), + } + file { '/usr/local/bin/pg-receive-file-from-backup': mode => '0555', source => 'puppet:///modules/roles/postgresql_server/pg-receive-file-from-backup', } - file { '/etc/dsa/pg-backup-file.conf': - content => template('roles/postgresql_server/pg-backup-file.conf.erb'), - } ssh::keygen {'postgres': } } diff --git a/modules/postgres/templates/backup_source/pg-backup-file.conf.erb b/modules/postgres/templates/backup_source/pg-backup-file.conf.erb new file mode 100644 index 000000000..ff6700464 --- /dev/null +++ b/modules/postgres/templates/backup_source/pg-backup-file.conf.erb @@ -0,0 +1,5 @@ +<%- if @hostname == "sibelius" then -%> +# use ipv4 +ssh_options="-oAddressFamily=inet" +<%- end %> +backuphost="debbackup@backuphost debbackup@storace" diff --git a/modules/roles/files/postgresql_server/pg-backup-file b/modules/roles/files/postgresql_server/pg-backup-file deleted file mode 100755 index 9a432e56b..000000000 --- a/modules/roles/files/postgresql_server/pg-backup-file +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2010, 2011, 2013, 2014 Peter Palfrader -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -# Archive a postgresql file (WAL or BASE) to the archive server $backuphost -# can be set in /etc/dsa/pg-backup-file.conf - -set -u - -backuphost=debbackup@storace -myhost="`hostname`" -self="`basename "$0"`[$$]" - -if [ "$#" != 3 ] ; then - echo >&2 "Usage: $self " - exit 1 -fi - -ssh_options="" -! [ -e /etc/dsa/pg-backup-file.conf ] || . /etc/dsa/pg-backup-file.conf - -cluster="$1" -what="$2" -file="$3" - -info() { - logger -p daemon.info -t "$self" "$1" -} - -croak() { - logger -s -p daemon.warn -t "$self" "$1" - exit 1 -} - -if ! [ -e "$file" ] ; then - croak "file $file does not exist" -fi - -size="`stat -c '%s' "$file"`" -checksum="" -bn="`basename "$file"`" -targetname="$cluster.$what.$bn" -logtuple_start="($myhost,$targetname,$size" -failures="" - -for target in $backuphost; do - if [ "${target#/}" != "$target" ]; then - info "Archiving to $target: ($targetname,$size)" - cp "$file" "$target/$myhost-$targetname" - else - [ -n "$checksum" ] || checksum="`sha512sum "$file" | awk '{print $1}'`" - info "Archiving to $target: ($myhost,$targetname,$size,$checksum)" - - ssh -C "$target" $ssh_options -o BatchMode=yes -o ServerAliveInterval=90 $myhost store-file pg "$targetname" "$size" "$checksum" < "$file" - if [ "$?" != 0 ]; then - failures="$failures $logtuple_start,$checksum,$target)" - fi - fi -done -if [ "$failures" != "" ]; then - croak "remote store for$failures failed." -fi diff --git a/modules/roles/templates/postgresql_server/pg-backup-file.conf.erb b/modules/roles/templates/postgresql_server/pg-backup-file.conf.erb deleted file mode 100644 index ff6700464..000000000 --- a/modules/roles/templates/postgresql_server/pg-backup-file.conf.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%- if @hostname == "sibelius" then -%> -# use ipv4 -ssh_options="-oAddressFamily=inet" -<%- end %> -backuphost="debbackup@backuphost debbackup@storace"