if [ "$1" == "pre-backup" ]; then # Remove any existing db dump and then create a new one rm -rf $DATA_DIR/postgres/postgres-backup source /baserow/data/.pgpass PGPASSWORD=$DATABASE_PASSWORD pg_dump -j 2 -h localhost -U baserow baserow --format=directory -f $DATA_DIR/postgres/postgres-backup exit fi if [ "$1" == "post-backup" ]; then # rm -rf $DATA_DIR/postgres/postgres-backup exit fi if [ "$1" == "pre-restore" ]; then pkill -STOP -f "webfrontend" pkill -STOP -f "celery" pkill -STOP -f "caddy" # Disconnect any remaining idle sessions from the 'baserow' database # This prevents "database is being accessed by other users" errors during pg_restore -c source /baserow/data/.pgpass PGPASSWORD=$DATABASE_PASSWORD psql -h localhost -U baserow -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'baserow' AND pid <> pg_backend_pid();" exit fi if [ "$1" == "post-restore" ]; then source /baserow/data/.pgpass PGPASSWORD=$DATABASE_PASSWORD pg_restore -j 2 -h localhost -U baserow -d baserow -c $DATA_DIR/postgres/postgres-backup pkill -CONT -f "webfrontend" pkill -CONT -f "celery" pkill -CONT -f "caddy" exit fi