Difference between revisions of "Pg dump"

From UVOO Tech Wiki
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")
 
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
 +
```
 +
#!/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
 +
```

Revision as of 22:40, 13 January 2023

pg_dump -h localhost -p 5432 -U -Ft --file=/tmp/path_$(date +%Y%m%d_%H%M%S).dump

Script wrapper example

#!/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