Skip to content

Commit f801006

Browse files
committed
[skip ci] fix: DB dump script
1 parent e660a1e commit f801006

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

scripts/get_prod_db.sh

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ CONTAINER=palaute_db
44
SERVICE_NAME=db
55
DB_NAME=postgres
66

7-
# JAMI_DB=jami-db
8-
9-
# current_date=$(date +"%Y%m%d")
10-
# JAMI_FILE_NAME="jami_${current_date}.sql.gz"
7+
JAMI_CONTAINER=jami-db
8+
JAMI_SERVICE_NAME=jami-db
9+
JAMI_DB_NAME=postgres
1110

1211
FOLDER_NAME="norppa"
12+
JAMI_FOLDER_NAME="jami"
1313

1414
PROJECT_ROOT=$(dirname $(dirname $(realpath "$0")))
1515
BACKUPS=$PROJECT_ROOT/backups/
@@ -29,21 +29,22 @@ if [ ! -f "$S3_CONF" ]; then
2929
echo "!! No config file for s3 bucket !!"
3030
echo "Create file for path ~/.s3cfg and copy the credetials from version.helsinki.fi"
3131
echo ""
32-
return 0
32+
exit 0
3333
fi
3434

3535
echo "Creating backups folder"
3636
mkdir -p ${BACKUPS}
3737

38-
echo "Listing available backups in S3 bucket..."
38+
# --- Norppa Selection ---
39+
echo "Listing available Norppa backups in S3 bucket..."
3940
backup_files=$(s3cmd -c "$S3_CONF" ls "s3://psyduck/${FOLDER_NAME}/" | awk '{print $4}' | grep '\.sql\.gz$')
4041

4142
if [ -z "$backup_files" ]; then
42-
echo "No backup files found in S3 bucket!"
43+
echo "No Norppa backup files found in S3 bucket!"
4344
exit 1
4445
fi
4546

46-
echo "Available backups:"
47+
echo "Available Norppa backups:"
4748
select chosen_backup in $backup_files; do
4849
if [ -n "$chosen_backup" ]; then
4950
echo "You selected: $chosen_backup"
@@ -54,26 +55,59 @@ select chosen_backup in $backup_files; do
5455
fi
5556
done
5657

57-
echo "Fetching the selected dump: $FILE_NAME"
58+
# --- Jami Selection ---
59+
echo "Listing available Jami backups in S3 bucket..."
60+
jami_backup_files=$(s3cmd -c "$S3_CONF" ls "s3://psyduck/${JAMI_FOLDER_NAME}/" | awk '{print $4}' | grep '\.sql\.gz$')
61+
62+
if [ -z "$jami_backup_files" ]; then
63+
echo "No Jami backup files found in S3 bucket!"
64+
exit 1
65+
fi
66+
67+
echo "Available Jami backups:"
68+
select chosen_jami_backup in $jami_backup_files; do
69+
if [ -n "$chosen_jami_backup" ]; then
70+
echo "You selected: $chosen_jami_backup"
71+
JAMI_FILE_NAME=$(basename "$chosen_jami_backup")
72+
break
73+
else
74+
echo "Invalid selection. Please select a valid backup number."
75+
fi
76+
done
77+
78+
79+
# --- Downloads ---
80+
echo "Fetching the selected Norppa dump: $FILE_NAME"
5881
s3cmd -c "$S3_CONF" get "$chosen_backup" "$BACKUPS"
5982

6083
if [ ! -f "${BACKUPS}${FILE_NAME}" ]; then
6184
echo "Download failed or file not found: ${BACKUPS}${FILE_NAME}"
6285
exit 1
6386
fi
6487

88+
echo "Fetching the selected Jami dump: $JAMI_FILE_NAME"
89+
s3cmd -c "$S3_CONF" get "$chosen_jami_backup" "$BACKUPS"
90+
91+
if [ ! -f "${BACKUPS}${JAMI_FILE_NAME}" ]; then
92+
echo "Download failed or file not found: ${BACKUPS}${JAMI_FILE_NAME}"
93+
exit 1
94+
fi
95+
96+
# --- Reset and Start ---
6597
echo "Removing database and related volume"
6698
docker-compose -f $DOCKER_COMPOSE down -v
6799

68-
echo "Starting postgres in the background"
69-
docker-compose -f $DOCKER_COMPOSE up -d $SERVICE_NAME
100+
echo "Starting postgres containers in the background"
101+
docker-compose -f $DOCKER_COMPOSE up -d $SERVICE_NAME $JAMI_SERVICE_NAME
70102

103+
# --- Populate Norppa ---
71104
retry docker-compose -f $DOCKER_COMPOSE exec $SERVICE_NAME pg_isready --dbname=$DB_NAME
72105

73106
echo "Populating ${FOLDER_NAME}"
74107
docker exec -i $CONTAINER /bin/bash -c "gunzip | psql -U postgres" < ${BACKUPS}${FILE_NAME}
75108

76-
# retry docker compose -f $DOCKER_COMPOSE exec $JAMI_DB pg_isready --dbname=$JAMI_DB
109+
# --- Populate Jami ---
110+
retry docker-compose -f $DOCKER_COMPOSE exec $JAMI_SERVICE_NAME pg_isready --dbname=$JAMI_DB_NAME
77111

78-
# echo "Populating Jami"
79-
# docker exec -i $JAMI_DB /bin/bash -c "gunzip | psql -U postgres" < ${BACKUPS}${JAMI_FILE_NAME}
112+
echo "Populating ${JAMI_FOLDER_NAME}"
113+
docker exec -i $JAMI_CONTAINER /bin/bash -c "gunzip | psql -U postgres" < ${BACKUPS}${JAMI_FILE_NAME}

0 commit comments

Comments
 (0)