From a63238aa67241b06bf0f6979ca14307e86930064 Mon Sep 17 00:00:00 2001 From: Adrian Fraiha Date: Thu, 18 Mar 2021 13:00:39 -0400 Subject: [PATCH 1/3] Add command to sync DB with prod --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 35c2f2f03..33c1ac6cc 100644 --- a/Makefile +++ b/Makefile @@ -114,6 +114,8 @@ install: conda # pip install git+https://github.com/mskcc/beagle_cli.git@develop # pip install -r requirements-cli.txt # <- what happened to this file? +BEAGLE_BACKUP_DB_FOLDER=/juno/work/ci/beagle_backups/ + export ENVIRONMENT=dev # ~~~~~ Set Up Demo Postgres Database for Dev ~~~~~ # export BEAGLE_DB_NAME=db @@ -179,6 +181,11 @@ db-restore: db-inter: psql -p "$(PGPORT)" -U "$(PGUSER)" -W "$(PGDATABASE)" +db-sync-prod: + LATEST_DUMP=`ssh voyager ls -Art $(BEAGLE_BACKUP_DB_FOLDER) | tail -n 1` && \ + rsync --progress voyager:$(BEAGLE_BACKUP_DB_FOLDER)$$LATEST_DUMP . && \ + psql $(PGDATABASE) < $$LATEST_DUMP + # ~~~~~~ Celery tasks & RabbitMQ setup ~~~~~ # # !! need to start RabbitMQ before celery, and both before running Django app servers !! From ce6aac1aae2d866daae28621613a92ee6630a5ca Mon Sep 17 00:00:00 2001 From: Adrian Fraiha Date: Thu, 18 Mar 2021 14:38:45 -0400 Subject: [PATCH 2/3] use pg_restore instead --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 33c1ac6cc..4cee21095 100644 --- a/Makefile +++ b/Makefile @@ -174,7 +174,7 @@ db-backup: $(DB_BACKUP_DIR) db-restore: @echo ">>> restoring db from DBFILE: $(DBFILE)" if [ -n "$(DBFILE)" ]; then \ - psql "$(PGDATABASE)" < "$(DBFILE)" ; fi + pg_restore -d "$(PGDATABASE)" < "$(DBFILE)" ; fi # interactive Postgres console # use command `\dt` to show all tables @@ -184,7 +184,7 @@ db-inter: db-sync-prod: LATEST_DUMP=`ssh voyager ls -Art $(BEAGLE_BACKUP_DB_FOLDER) | tail -n 1` && \ rsync --progress voyager:$(BEAGLE_BACKUP_DB_FOLDER)$$LATEST_DUMP . && \ - psql $(PGDATABASE) < $$LATEST_DUMP + pg_restore -d $(PGDATABASE) < $$LATEST_DUMP # ~~~~~~ Celery tasks & RabbitMQ setup ~~~~~ # From 7accfd3e62ec7012af1b3019d19895d263ed28ed Mon Sep 17 00:00:00 2001 From: Adrian Fraiha Date: Mon, 22 Mar 2021 19:26:05 -0400 Subject: [PATCH 3/3] fix pg_restore --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4cee21095..8e70ac2cc 100644 --- a/Makefile +++ b/Makefile @@ -174,7 +174,7 @@ db-backup: $(DB_BACKUP_DIR) db-restore: @echo ">>> restoring db from DBFILE: $(DBFILE)" if [ -n "$(DBFILE)" ]; then \ - pg_restore -d "$(PGDATABASE)" < "$(DBFILE)" ; fi + pg_restore -h $(PGHOST) -p $(PGPORT) --no-privileges --no-owner --clean -d $(PGDATABASE) < "$(DBFILE)" ; fi # interactive Postgres console # use command `\dt` to show all tables