-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c24ca8
commit 0db4d14
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
API_TOKEN= | ||
TESTER_EMAILS='' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
.env | ||
*.sql.gz | ||
*.sql | ||
backup | ||
|
||
# Logs | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copy contents to .env in this directory and fill in the values | ||
|
||
# Your ad-username | ||
USERNAME= | ||
|
||
APP_NAME=toppi | ||
DB_NAME=toppi | ||
CONTAINER_NAME=toppi_db | ||
LOCAL_DB_USER=toppi | ||
LOCAL_DB_NAME=toppi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
PROJECT_ROOT=$(git rev-parse --show-toplevel) | ||
BACKUPS=$PROJECT_ROOT/backups/ | ||
|
||
echo "Found project root" $PROJECT_ROOT | ||
|
||
# Get variables from .env file | ||
export $(grep -v '^#' $PROJECT_ROOT/scripts/.env | xargs) | ||
|
||
echo "Found env variables from .env file" | ||
|
||
# Login to OC | ||
oc login -u $USERNAME https://api.ocp-prod-0.k8s.it.helsinki.fi:6443 | ||
|
||
# Print login success | ||
echo "Login successful" | ||
|
||
# Read db password from user | ||
DB_PASSWORD="" | ||
echo "Enter the possu database password \n(see https://version.helsinki.fi/toska/dokumentaatio/-/blob/master/passwords.md?ref_type=heads)" | ||
read -s DB_PASSWORD | ||
|
||
# Download backup | ||
oc exec -it $(oc get pods -l deployment=db-tools -o jsonpath='{.items[0].metadata.name}') -- pg_dump postgres://$DB_NAME:$DB_PASSWORD@possu-toska.it.helsinki.fi:5432/$APP_NAME | gzip -c > $DB_NAME.sql.gz | ||
|
||
# Remove and recreate the database, then load the backup | ||
docker-compose down db -v | ||
docker-compose up -d db | ||
|
||
# Wait for the database to be ready | ||
while ! docker-compose exec db pg_isready --dbname=$DB_NAME; do | ||
echo "Waiting for the database to be ready..." | ||
sleep 1 | ||
done | ||
|
||
# Load the backup | ||
docker exec -i $CONTAINER_NAME /bin/bash -c "gunzip | psql -U $LOCAL_DB_USER -d $LOCAL_DB_NAME" < $DB_NAME.sql.gz |