Improve usage of pg_dump in backup

This commit is contained in:
Tobias Reisinger 2026-02-01 20:33:25 +01:00
parent 731647be9d
commit f7936633e5
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
3 changed files with 13 additions and 14 deletions

View file

@ -1,20 +1,19 @@
#!/usr/bin/env bash
cd "$1"
if [ "$2" != "before" ]; then
exit 0
fi
cd "$1"
sudo rm -r "$1"/*.dump || true
sudo chown postgres:postgres "$1"
postgres_tables=$(sudo -u postgres psql -Atc "SELECT datname FROM pg_database WHERE datistemplate = false;")
for i in $postgres_tables
do
printf "dumping %s ..." "$i"
sudo -u postgres pg_dump "$i" | gzip >"pg_dump_$i.sql.gz"
sudo -u postgres pg_dump -Fd -C -Zzstd:5 -j2 -f"pg_dump_$i.dump" "$i"
echo " done"
done
echo -n "dumping all ..."
sudo -u postgres pg_dumpall | gzip >"pg_dumpall.sql.gz"
echo " done"