DATE date d- m- DUMP_DIR export home stud dbDumps DATE pfexec rm -rf D

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
DATE=$(date +'%d-%m-%y')
DUMP_DIR=/export/home/stud/dbDumps/$DATE
pfexec rm -rf $DUMP_DIR
pfexec mkdir $DUMP_DIR
pfexec chown postgres:postgres $DUMP_DIR
DB_NAMES=$(pfexec su - postgres -c "psql -l" | cut -d "|" -f1 | sed '$d' | sed '$d;1,4d')
for DB_NAME in $DB_NAMES; do
echo "DUMPING DB: $DB_NAME"
pfexec su - postgres "pg_dump -U postgres -d ${DB_NAME} -F c -f ${DUMP_DIR}/${DB_NAME}.dump"
done
pfexec su - postgres "pg_dumpall | bzip2 -c > ${DUMP_DIR}/data.bcp.bz2"
pfexec find /var/postgres/10/data -name \*.conf -exec cp {} $DUMP_DIR \;