File: suite

package info (click to toggle)
pgbackrest 2.58.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,056 kB
  • sloc: ansic: 128,636; xml: 19,653; perl: 11,498; pascal: 3,279; sh: 91; sql: 32; makefile: 23
file content (93 lines) | stat: -rwxr-xr-x 1,812 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash

# This test expects postgresql version 9.3 or higher.

set -e

cleanfiles()
{
  echo "Cleaning files..."
  rm -rf $tempdir
  rm -f $tempconf
  rm -rf $templock
  rm -rf $templog
}

pgbackresttest()
{
  pgbackrest --stanza=demo --log-level-console=info --config=$tempconf stanza-create
  pgbackrest --stanza=demo --log-level-console=info --config=$tempconf check
  pgbackrest --stanza=demo --log-level-console=info --config=$tempconf backup
  pgbackrest --config=$tempconf info
}

startvirtualenv()
{
  tempconf=$(mktemp)
  PGVIRTUAL=1 exec pg_virtualenv -t \
    -o "archive_command=pgbackrest --stanza=demo --config=$tempconf archive-push %p" \
    -o "archive_mode=on" \
    -o "listen_addresses=*" \
    -o "log_line_prefix=" \
    -o "max_wal_senders=3" \
    -o "wal_level=hot_standby" \
    -i "-A trust -k" "$0" "$tempconf"
}

checkdirvirt()
{
  virtdir=$(psql -AqtX -c "SHOW data_directory";)
  if [ -z "$virtdir" ]
    then
      echo "Couldn't find temporary dir..."
      exit 1
  fi
}

createfilesdirs()
{
  tempdir=$(mktemp -d)
  templog=$(mktemp -d)
  templock=$(mktemp -d)
}

modifypgbackconf()
{
cat > $tempconf << EOL
[demo]
db-path=$virtdir
db-user=$PGUSER
db-port=$PGPORT
log-path=$templog
lock-path=$templock
[global]
repo-path=$tempdir
retention-full=2
EOL
}

trap cleanfiles 0 2 3 15

##########################################################

# pgBackRest need to run as cluster owner.
# pg_virtualenv restarts create the cluster as user postgres if we run
# as root. So, restarting as postgres if we run as root looks like a
# good idea.
if [ $(whoami) == "root" ]; then
  su - postgres -c "exec $0 $*"
  exit $?
fi

if [ ! -z "$1" ]
  then
    tempconf=$1
fi

if [ -z "$PGVIRTUAL" ]; then
    startvirtualenv
fi
checkdirvirt
createfilesdirs
modifypgbackconf
pgbackresttest