+pg-export.sh
This commit is contained in:
parent
9f6f10f6a9
commit
5d5ada8f80
|
@ -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
|
Loading…
Reference in New Issue