Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |