Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the postgresql module #1

Merged
merged 1 commit into from Apr 23, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions modules/postgresql.sh
@@ -0,0 +1,30 @@
#!/bin/bash

mod_postgresql() {
verbose "[POSTGRESQL] running..."
for db in "${POSTGRESQL_TARGETS[@]}"; do
opts=""
[ "$POSTGRESQL_USER" != "" ] && opts="$opts -U ${POSTGRESQL_USER}"
[ "$POSTGRESQL_HOST" != "" ] && opts="$opts -h ${POSTGRESQL_HOST}"
[ "$POSTGRESQL_PORT" != "" ] && opts="$opts -p ${POSTGRESQL_PORT}"
if [ "$db" = "__ALL__" ]; then
opts="$opts -A"
dbname="all"
else
opts="$opts $db"
dbname=$db
fi
fn="${BACKUP_DIR}/$HOSTNAME-postgresql-${dbname}-$TODAY.sql.bz2"
verbose "[POSTGRESQL] backup up database: $db"
if [ "$POSTGRESQL_ENCRYPTION_KEY" ]; then
# decrypt with 'openssl enc -d -bf -pass pass:<password> -in infile -out outfile'
verbose "[POSTGRESQL] cmd: pg_dump $opts | bzip2 | openssl enc -e -salt -bf -pass pass:$POSTGRESQL_ENCRYPTION_KEY >$fn"
pg_dump $opts | bzip2 | openssl enc -e -salt -bf -pass pass:$POSTGRESQL_ENCRYPTION_KEY >$fn
else
verbose "[POSTGRESQL] cmd: pg_dump $opts | bzip2 >$fn"
pg_dump $opts | bzip2 >$fn
fi
[ $? -eq 0 ] || die "ERROR: command did not complete successfully"
NEW_BACKUPS="$NEW_BACKUPS $fn"
done
}