Difference between revisions of "Pg dump"
Jump to navigation
Jump to search
| Line 3: | Line 3: | ||
Script wrapper example | Script wrapper example | ||
| + | |||
| + | .env | ||
| + | ``` | ||
| + | export PGHOST=zabbix-postgresql.zabbix.svc.cluster.local | ||
| + | export PGPORT=5432 | ||
| + | export PGDATABASE=zabbix | ||
| + | export PGUSER=zabbix | ||
| + | export PGPASSWORD=mypass | ||
| + | # export PGREQUIRESSL=true | ||
| + | export PGSSLMODE=prefer | ||
| + | ``` | ||
| + | |||
``` | ``` | ||
#!/bin/bash | #!/bin/bash | ||
Revision as of 22:42, 13 January 2023
pg_dump -h localhost -p 5432 -U
Script wrapper example
.env
export PGHOST=zabbix-postgresql.zabbix.svc.cluster.local export PGPORT=5432 export PGDATABASE=zabbix export PGUSER=zabbix export PGPASSWORD=mypass # export PGREQUIRESSL=true export PGSSLMODE=prefer
#!/bin/bash
set -eu
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
excludeTables(){
file=${current_time}.${PGHOST}.${PGDATABASE}.dump.excludetables.sql.gz
echo $file
pg_dump \
-d ${PGDATABASE} \
--file=${file} \
--compress=6 \
--verbose \
--exclude-table-data '*.trends*' \
--exclude-table-data '*.history*'
}
# Other options
# --exclude-table-data '*.auditlog*' \
# --exclude-table-data '*.trends*' \
# --format=custom \
# --blobs \
# --compress=6 \
allTables(){
file=${current_time}.${PGHOST}.${PGDATABASE}.dump.alltables.sql.c6.gz
pg_dump \
-d ${PGDATABASE} \
--file=$file \
--format=custom \
--blobs \
--verbose \
--compress=6
}
excludeTables
# allTables