+pg-export.sh

This commit is contained in:
Dym Sohin 2024-02-24 14:34:44 +01:00
parent 9f6f10f6a9
commit 5d5ada8f80
1 changed files with 24 additions and 0 deletions

24
pg-export.sh Executable file
View File

@ -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