Difference between revisions of "Pg dump"
Jump to navigation
Jump to search
(Created page with "pg_dump -h localhost -p 5432 -U <MY_PG_Username> -Ft <MY_DB_Name> --file=/tmp/path_$(date +%Y%m%d_%H%M%S).dump") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
pg_dump -h localhost -p 5432 -U <MY_PG_Username> -Ft <MY_DB_Name> --file=/tmp/path_$(date +%Y%m%d_%H%M%S).dump | pg_dump -h localhost -p 5432 -U <MY_PG_Username> -Ft <MY_DB_Name> --file=/tmp/path_$(date +%Y%m%d_%H%M%S).dump | ||
| + | |||
| + | |||
| + | 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 PGSSLMODE=require | ||
| + | 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 | ||
| + | ``` | ||
Latest revision as of 16:39, 9 March 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 PGSSLMODE=require 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