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