25 lines
536 B
Bash
25 lines
536 B
Bash
|
#!/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
|