2005-12-28 21:19:29 +01:00
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2009-05-22 15:27:09 +02:00
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
2005-12-28 20:59:12 +01:00
2005-08-09 22:59:20 +02:00
HELPERS="$HELPERS pgsql:postgresql_database_backup"
do_pgsql_vserver() {
2005-11-29 11:10:53 +01:00
choose_one_vserver "$pgsql_title"
[ $? = 0 ] || return 1
2005-08-09 22:59:20 +02:00
pgsql_vsname="vsname = $REPLY"
}
do_pgsql_databases() {
2005-11-29 11:11:04 +01:00
REPLY=
while [ -z "$REPLY" ]; do
formBegin "$pgsql_title: databases"
formItem "Database:"
2009-05-22 14:50:52 +02:00
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
2005-11-29 11:11:04 +01:00
formDisplay
[ $? = 0 ] || return 1
pgsql_databases="databases = "
for i in $REPLY; do
2009-05-22 14:50:52 +02:00
[ -n "$i" ] && pgsql_databases="$pgsql_databases $i"
2005-11-29 11:11:04 +01:00
done
2005-08-09 22:59:20 +02:00
done
}
pgsql_wizard() {
# constants
pgsql_title="PostgreSQL action wizard"
2005-11-29 11:10:53 +01:00
# backup the host system or a Vserver?
choose_host_or_one_vserver "$pgsql_title"
[ $? = 0 ] || return 1
if [ $host_or_vservers == vservers ]; then
do_pgsql_vserver
[ $? = 0 ] || return 1
fi
2005-08-09 22:59:20 +02:00
# backupdir
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"
[ $? = 1 ] && return
pgsql_backupdir="backupdir = $REPLY"
# databases
booleanBox "$pgsql_title" "Do you want to backup the whole cluster? If not, you'll be offered to choose the databases to backup."
if [ $? = 0 ]; then
pgsql_databases="databases = all"
else
do_pgsql_databases
2005-11-29 11:10:53 +01:00
[ $? = 0 ] || return 1
2005-08-09 22:59:20 +02:00
fi
# compress
booleanBox "$pgsql_title" "Do you want to compress the backups?"
if [ $? = 0 ]; then
pgsql_compress="compress = yes"
else
pgsql_compress="compress = no"
fi
2010-10-12 02:53:00 +02:00
# pg_dump format, defaults to plain, custom is recommended by PostgreSQL
menuBox "$pgsql_title" "Choose a pg_dump format:" \
plain "Default plain-text sql script, use with psql." \
tar "More flexible than the plain, use with pg_restore." \
custom "The most flexible format, use with pg_restore."
if [ $? = 0 ]; then
result="$REPLY"
case "$result" in
"tar") pgsql_format="format = tar";;
"custom") pgsql_format="format = custom";;
*) pgsql_format = "format = plain";;
esac
fi
2005-08-09 22:59:20 +02:00
# write config file
get_next_filename $configdirectory/20.pgsql
cat >> $next_filename <<EOF
### backupninja PostgreSQL config file ###
# vsname = <vserver> (no default)
# what vserver to operate on, only used if vserver = yes in /etc/backupninja.conf
# if you do not specify a vsname the host will be operated on
# Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir.
2005-11-29 11:10:53 +01:00
EOF
if [ $host_or_vservers == vservers ]; then
echo -e "$pgsql_vsname\n" >> $next_filename
fi
2005-08-09 22:59:20 +02:00
2005-11-29 11:10:53 +01:00
cat >> $next_filename <<EOF
2005-08-09 22:59:20 +02:00
# backupdir = <dir> (default: /var/backups/postgres)
# where to dump the backups
$pgsql_backupdir
# databases = < all | db1 db2 db3 > (default = all)
2009-05-22 14:50:52 +02:00
# which databases to backup. should either be the word 'all' or a
2005-08-09 22:59:20 +02:00
# space separated list of database names.
# Note: when using 'all', pg_dumpall is used instead of pg_dump, which means
# that cluster-wide data (such as users and groups) are saved.
$pgsql_databases
# compress = < yes | no > (default = yes)
2009-05-22 14:50:52 +02:00
# if yes, compress the pg_dump/pg_dumpall output.
2005-08-09 22:59:20 +02:00
$pgsql_compress
2010-10-12 02:53:00 +02:00
# format = < plain | tar | custom > (default = plain)
# plain - Output a plain-text SQL script file with the extension .sql.
# When dumping all databases, a single file is created via pg_dumpall.
# tar - Output a tar archive suitable for input into pg_restore. More
# flexible than plain and can be manipulated by standard Unix tools
# such as tar. Creates a globals.sql file and an archive per database.
# custom - Output a custom PostgreSQL pg_restore archive. This is the most
# flexible format allowing selective import and reordering of database
# objects at the time the database is restored via pg_restore. This
# option creates a globals.sql file containing the cluster role and
# other information dumped by pg_dumpall -g and a pg_restore file
# per selected database. See the pg_dump and pg_restore man pages.
$pgsql_format
2006-11-01 19:26:41 +01:00
### You can also set the following variables in backupninja.conf:
2010-10-12 02:53:00 +02:00
# PSQL: psql path (default: /usr/bin/psql)
2006-11-01 19:26:41 +01:00
# PGSQLDUMP: pg_dump path (default: /usr/bin/pg_dump)
# PGSQLDUMPALL: pg_dumpall path (default: /usr/bin/pg_dumpall)
# PGSQLUSER: user running PostgreSQL (default: postgres)
2005-08-09 22:59:20 +02:00
EOF
2005-11-05 00:35:29 +01:00
chmod 600 $next_filename
2005-08-09 22:59:20 +02:00
}