#!/bin/bash
# PostgreSQL server host
HOST=""
# PostgreSQL user
USER=""
# PostgreSQL port
PORT=""
# PostgreSQL database name
DB=""
# Schema list
SCHEMAS=("")
# Password for the PostgreSQL user
export PGPASSWORD=""
echo '数据库地址:'$HOST
echo '数据库名称:'$DB
# Iterate over the schema list
for SCHEMA in "${SCHEMAS[@]}"
do
# Create directories for structure and data if they do not exist
mkdir -p ./$SCHEMA/structure
mkdir -p ./$SCHEMA/data
set -x
# Backup structure
echo '开始备份'$SCHEMA'结构'
pg_dump -h $HOST -U $USER -p $PORT -d $DB -n $SCHEMA -s -Z 3 -Fd -j 1 --no-owner --no-privileges -f ./$SCHEMA/structure
# Backup data
echo '开始备份'$SCHEMA'数据'
pg_dump -h $HOST -U $USER -p $PORT -d $DB -n $SCHEMA -a -Z 2 -Fd -j 1 --no-owner --no-privileges -f ./$SCHEMA/data
set +x
done