Skip to content
Snippets Groups Projects
Commit 35fdb41a authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'pgsql-snapshot-fallback' into 'master'

pgsql.backup - no subshell to fetch backup status

See merge request !150
parents 0f18be88 198738d8
No related branches found
No related tags found
1 merge request!150pgsql.backup - no subshell to fetch backup status
...@@ -56,66 +56,65 @@ function pgsql.backup(){ ...@@ -56,66 +56,65 @@ function pgsql.backup(){
# ----- GO # ----- GO
# prevent could not change directory to "/root": Permission denied # prevent could not change directory to "/root": Permission denied
( cd /tmp
cd /tmp
# Detect a readonly or writeable postgres host.
# Detect a readonly or writeable postgres host. TESTDB="imlbackup_createtest"
TESTDB="imlbackup_createtest" su ${PGUSER} -c "dropdb ${TESTDB}" >/dev/null 2>&1
su ${PGUSER} -c "dropdb ${TESTDB}" >/dev/null 2>&1 if su ${PGUSER} -c "psql ${BACKUP_PARAMS} -c \"CREATE DATABASE ${TESTDB};\"" >/dev/null 2>&1
if su ${PGUSER} -c "psql ${BACKUP_PARAMS} -c \"CREATE DATABASE ${TESTDB};\"" >/dev/null 2>&1 then
then bUseSnapshot=1
bUseSnapshot=1 su ${PGUSER} -c "dropdb ${TESTDB}"
su ${PGUSER} -c "dropdb ${TESTDB}" echo "INFO: enabling snapshots"
echo "INFO: enabling snapshots" else
else echo "INFO: create database failed for snapshots - dumping databases directly"
echo "INFO: create database failed for snapshots - dumping databases directly" fi
fi
sSqlGetDblist="select datname from pg_database where not datistemplate and datallowconn order by datname;" sSqlGetDblist="select datname from pg_database where not datistemplate and datallowconn order by datname;"
for DATABASE in $( su ${PGUSER} -c "psql ${BACKUP_PARAMS} -At -c '$sSqlGetDblist' postgres" 2>/dev/null | grep -v "^$snapshotprefix" ) for DATABASE in $( su ${PGUSER} -c "psql ${BACKUP_PARAMS} -At -c '$sSqlGetDblist' postgres" 2>/dev/null | grep -v "^$snapshotprefix" )
do do
echo -n "__DB__${SERVICENAME} backup $DATABASE ... " echo -n "__DB__${SERVICENAME} backup $DATABASE ... "
bUseSnapshot4DB=$bUseSnapshot bUseSnapshot4DB=$bUseSnapshot
SNAPSHOTDB="${DATABASE}" SNAPSHOTDB="${DATABASE}"
test $bUseSnapshot4DB -eq 1 && SNAPSHOTDB="${snapshotprefix}${DATABASE}" test $bUseSnapshot4DB -eq 1 && SNAPSHOTDB="${snapshotprefix}${DATABASE}"
OUTFILE="${BACKUP_TARGETDIR}/$(get_outfile ${DATABASE}).sql" OUTFILE="${BACKUP_TARGETDIR}/$(get_outfile ${DATABASE}).sql"
myrc=0 myrc=0
# drop snapshot db first - just in case # drop snapshot db first - just in case
if [ $bUseSnapshot4DB -eq 1 ]; then if [ $bUseSnapshot4DB -eq 1 ]; then
echo -n " snapshot ... " echo -n " snapshot ... "
su ${PGUSER} -c "dropdb ${SNAPSHOTDB}" >/dev/null 2>&1 su ${PGUSER} -c "dropdb ${SNAPSHOTDB}" >/dev/null 2>&1
if ! su ${PGUSER} -c "psql ${BACKUP_PARAMS} -c \"CREATE DATABASE ${SNAPSHOTDB} WITH TEMPLATE ${DATABASE};\"" >/dev/null 2>&1; then if ! su ${PGUSER} -c "psql ${BACKUP_PARAMS} -c \"CREATE DATABASE ${SNAPSHOTDB} WITH TEMPLATE ${DATABASE};\"" >/dev/null; then
echo -n " nope, using origin ... " echo -n "Fallback using origin ... "
bUseSnapshot4DB=0 bUseSnapshot4DB=0
SNAPSHOTDB="${DATABASE}" SNAPSHOTDB="${DATABASE}"
fi
fi fi
if [ $myrc -eq 0 ]; then fi
if [ $myrc -eq 0 ]; then
echo -n "backup ... "
if su ${PGUSER} -c "pg_dump ${BACKUP_PARAMS} -Fp ${SNAPSHOTDB} >$OUTFILE"; then echo -n "backup ... "
fetchrc >/dev/null if su ${PGUSER} -c "pg_dump ${BACKUP_PARAMS} -Fp ${SNAPSHOTDB} >$OUTFILE"; then
test $bUseSnapshot4DB -eq 1 && ( fetchrc >/dev/null
echo -n "delete snapshot ... " test $bUseSnapshot4DB -eq 1 && (
su ${PGUSER} -c "dropdb ${SNAPSHOTDB}" echo -n "delete snapshot ... "
) su ${PGUSER} -c "dropdb ${SNAPSHOTDB}"
)
db._compressDumpfile "$OUTFILE"
else db._compressDumpfile "$OUTFILE"
fetchrc
test $bUseSnapshot4DB -eq 1 && su ${PGUSER} -c "dropdb ${SNAPSHOTDB}"
fi
else else
cecho error "ERROR!" fetchrc
test $bUseSnapshot4DB -eq 1 && su ${PGUSER} -c "dropdb ${SNAPSHOTDB}"
fi fi
else
cecho error "ERROR!"
fi
done done
) cd - >/dev/null
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment