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