root/trunk/infrastructure/misc/create-ircservices-backup

Revision 314, 2.0 kB (checked in by weasel, 23 months ago)

trap so that we always run pg_stop_backup

  • Property svn:executable set to *
Line 
1#!/bin/bash
2
3# Copyright 2007 Peter Palfrader <peter@palfrader.org>
4#
5# Permission is hereby granted, free of charge, to any person obtaining
6# a copy of this software and associated documentation files (the
7# "Software"), to deal in the Software without restriction, including
8# without limitation the rights to use, copy, modify, merge, publish,
9# distribute, sublicense, and/or sell copies of the Software, and to
10# permit persons to whom the Software is furnished to do so, subject to
11# the following conditions:
12#
13# The above copyright notice and this permission notice shall be
14# included in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24# create a backup of the services database, excluding the log (transaction/write ahead logs) directory
25# those are handled separately
26
27set -e
28
29umask 077
30
31HOST=`hostname`
32CLUSTER="ircservices"
33VERSION="8.3"
34DATE=$(date "+%Y%m%d")
35PORT=5433
36
37LABEL="$DATE-$HOST-$CLUSTER-$VERSION-backup"
38ID=`sudo -u postgres psql -p "$PORT" --tuples-only --command "SELECT pg_start_backup('$LABEL');"`
39trap "sudo -u postgres psql -q -p '$PORT' --command 'SELECT pg_stop_backup();'" exit
40ID=`echo $ID | sed -e 's/[^a-zA-Z0-9]/_/g'`
41
42cd /var/lib/postgresql
43TARBALL="$LABEL-$ID.tar.bz2"
44if tar cjf "$TARBALL" --exclude "$VERSION/$CLUSTER/pg_xlog" "$VERSION/$CLUSTER"; then
45        :  # all went well
46else
47        if [ "$?" = 1 ]; then
48                echo "Ignoring tar exit code of 1" >&2
49        else
50                echo "Dying because tar exited with an exit code not in {0, 1}" >&2
51                exit 1
52        fi
53fi
54
55chown postgres: "$TARBALL"
56sudo -u postgres scp "$TARBALL" backup:ircservices-tarballs/
57rm "$TARBALL"
Note: See TracBrowser for help on using the browser.