Skip to content

Commit

Permalink
chore: fix backup script
Browse files Browse the repository at this point in the history
backup all schema in one step
otherwise FK between embedding and public are not enforced
  • Loading branch information
raphael0202 committed Jul 19, 2024
1 parent 03e8213 commit 1a03dd8
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions scripts/backup_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
set -euo pipefail
IFS=$'\n\t'

echo "Performing Robotoff PostgreSQL backup"
echo "$(date -u '+%Y-%m-%d %H:%M:%S') :: Performing Robotoff PostgreSQL backup"

BASE_DIR=/opt/robotoff-backups/postgres
echo "Creating $BASE_DIR if it doesn't exist"
echo "$(date -u '+%Y-%m-%d %H:%M:%S') :: Creating $BASE_DIR if it doesn't exist"
mkdir -p $BASE_DIR

# We backup the two schemas in distinct backups, because the embedding schema is huge
echo "Backing-up public schema..."
# Save the backup in progress in a temporary file so that the latest dump file is always valid
# Wait 10s max for the lock to be released (avoid concurrent dump)
pg_dump --lock-wait-timeout=10000 --schema public -F c -U postgres postgres -f $BASE_DIR/robotoff_postgres_public.dump.tmp
mv $BASE_DIR/robotoff_postgres_public.dump.tmp $BASE_DIR/robotoff_postgres_public.dump
echo "public schema completed"

echo "Backing-up embedding schema..."
pg_dump --lock-wait-timeout=10000 --schema embedding -F c -U postgres postgres -f $BASE_DIR/robotoff_postgres_embedding.dump.tmp
mv $BASE_DIR/robotoff_postgres_embedding.dump.tmp $BASE_DIR/robotoff_postgres_embedding.dump
echo "embedding schema completed"

echo "Backup completed"
pg_dump --lock-wait-timeout=10000 -F c -U postgres postgres -f $BASE_DIR/robotoff_postgres.dump.tmp
mv $BASE_DIR/robotoff_postgres.dump.tmp $BASE_DIR/robotoff_postgres.dump
echo "$(date -u '+%Y-%m-%d %H:%M:%S') :: back-up completed"

0 comments on commit 1a03dd8

Please sign in to comment.