Add a vim modeline with indentation settings.
[matthijs/upstream/backupninja.git] / handlers / pgsql.helper.in
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
3
4 HELPERS="$HELPERS pgsql:postgresql_database_backup"
5
6 do_pgsql_vserver() {
7    choose_one_vserver "$pgsql_title"
8    [ $? = 0 ] || return 1
9    pgsql_vsname="vsname = $REPLY"
10 }
11
12 do_pgsql_databases() {
13    REPLY=
14    while [ -z "$REPLY" ]; do
15       formBegin "$pgsql_title: databases"
16          formItem "Database:"
17          formItem "Database:"
18          formItem "Database:"
19          formItem "Database:"
20          formItem "Database:"
21          formItem "Database:"
22          formItem "Database:"
23          formItem "Database:"
24          formItem "Database:"
25          formItem "Database:"
26       formDisplay
27       [ $? = 0 ] || return 1
28       pgsql_databases="databases = "
29       for i in $REPLY; do
30          [ -n "$i" ] && pgsql_databases="$pgsql_databases $i"
31       done
32    done
33 }
34
35 pgsql_wizard() {
36
37     # constants
38    pgsql_title="PostgreSQL action wizard"
39
40    # backup the host system or a Vserver?
41    choose_host_or_one_vserver "$pgsql_title"
42    [ $? = 0 ] || return 1
43    if [ $host_or_vservers == vservers ]; then
44       do_pgsql_vserver
45       [ $? = 0 ] || return 1
46    fi
47
48    # backupdir
49    inputBox "$pgsql_title" "Directory where to store the backups:`[ -z \"$pgsql_vsname\" ] || echo \"\n(In respect to chosen vserver's root directory)\"`" "/var/backups/postgres"
50    [ $? = 1 ] && return
51    pgsql_backupdir="backupdir = $REPLY"
52
53    # databases
54    booleanBox "$pgsql_title" "Do you want to backup the whole cluster? If not, you'll be offered to choose the databases to backup."
55    if [ $? = 0 ]; then
56       pgsql_databases="databases = all"
57    else
58       do_pgsql_databases
59       [ $? = 0 ] || return 1
60    fi
61
62    # compress
63    booleanBox "$pgsql_title" "Do you want to compress the backups?"
64    if [ $? = 0 ]; then
65       pgsql_compress="compress = yes"
66    else
67       pgsql_compress="compress = no"
68    fi
69
70    # write config file
71    get_next_filename $configdirectory/20.pgsql
72    cat >> $next_filename <<EOF
73 ### backupninja PostgreSQL config file ###
74
75 # vsname = <vserver> (no default)
76 # what vserver to operate on, only used if vserver = yes in /etc/backupninja.conf
77 # if you do not specify a vsname the host will be operated on
78 # Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir.
79 EOF
80    if [ $host_or_vservers == vservers ]; then
81       echo -e "$pgsql_vsname\n" >> $next_filename
82    fi
83
84    cat >> $next_filename <<EOF
85 # backupdir = <dir> (default: /var/backups/postgres)
86 # where to dump the backups
87 $pgsql_backupdir
88
89 # databases = < all | db1 db2 db3 > (default = all)
90 # which databases to backup. should either be the word 'all' or a
91 # space separated list of database names.
92 # Note: when using 'all', pg_dumpall is used instead of pg_dump, which means
93 # that cluster-wide data (such as users and groups) are saved.
94 $pgsql_databases
95
96 # compress = < yes | no > (default = yes)
97 # if yes, compress the pg_dump/pg_dumpall output.
98 $pgsql_compress
99
100 ### You can also set the following variables in backupninja.conf:
101 # PGSQLDUMP: pg_dump path (default: /usr/bin/pg_dump)
102 # PGSQLDUMPALL: pg_dumpall path (default: /usr/bin/pg_dumpall)
103 # PGSQLUSER: user running PostgreSQL (default: postgres)
104
105 EOF
106    chmod 600 $next_filename
107
108 }