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