From 5d5ada8f805cd638658372c304cd45ccba590463 Mon Sep 17 00:00:00 2001 From: Dym Sohin Date: Sat, 24 Feb 2024 14:34:44 +0100 Subject: [PATCH] +pg-export.sh --- pg-export.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 pg-export.sh diff --git a/pg-export.sh b/pg-export.sh new file mode 100755 index 0000000..ef57ab4 --- /dev/null +++ b/pg-export.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env zsh + +PG_C="pg_dump -U postgres -Z0 -j 4 -Fd" +DATE=`date +%Y%m%d` + +rm -rf "/bak/db_current" +mkdir -p "/bak/db_current/" +mkdir -p "/bak/db-$DATE/" +chown -R postgres:postgres "/bak/db_current" +chmod g+s -R "/bak/db_current" + + +DB_TABLES=( + forgejo + inventory + gts +) +for DB_TABLE in $DB_TABLES ; do + echo "exporting $DB_TABLE" + su - postgres -c "$PG_C $DB_TABLE -f /bak/db_current/$DB_TABLE/" \ + && echo "compacting $DB_TABLE" \ + && tar -zcvf "/bak/db-$DATE/$DB_TABLE.tgz" \ + "/bak/db_current/$DB_TABLE/" +done