-
Notifications
You must be signed in to change notification settings - Fork 4
/
load_db_build_solr
84 lines (70 loc) · 3.73 KB
/
load_db_build_solr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 --stage | --prod"
exit 1
}
# Check if exactly one argument is provided
if [ "$#" -ne 1 ]; then
echo "Error: Exactly one argument is required."
usage
fi
# Validate the argument
ENV_FLAG="$1"
if [[ "$ENV_FLAG" != "--stage" && "$ENV_FLAG" != "--prod" ]]; then
echo "Error: Invalid argument '$ENV_FLAG'."
usage
fi
# Step 1: Define the S3 bucket and file path for the database backup
echo "Step 1: Define the S3 bucket and file path for the database backup"
BUCKET_NAME="agr-db-backups"
FILE_PATH="alliancemine/stage/" # Remains unchanged
# Step 2: List objects in the S3 bucket, sort by last modified date, and get the most recent file
echo "Step 2: Listing objects in S3 bucket and getting the most recent backup file"
export DB_FILE=$(aws s3api list-objects-v2 --bucket "$BUCKET_NAME" --query "reverse(sort_by(Contents[?contains(Key, \`$FILE_PATH\`)], &LastModified))[:1].Key" --output=text)
echo "Most recent backup file: $DB_FILE"
# Step 3: Copy the most recent database backup file from S3 to the local machine
echo "Step 3: Copying the most recent database backup file from S3 to the local machine"
aws s3 cp s3://$BUCKET_NAME/$DB_FILE /root/data/db_backup.dump --no-progress
echo "Backup file copied to /root/data/db_backup.dump"
# Step 4: Create a new database for the restoration
echo "Step 4: Creating a new database 'alliancemine'"
createdb -U postgres -h agr.stage.alliancemine.postgres.server alliancemine
echo "Database 'alliancemine' created"
# Step 5: Restore the database from the backup file
echo "Step 5: Restoring the database from the backup file"
pg_restore -U postgres -O -x -d alliancemine -h agr.stage.alliancemine.postgres.server -j 8 /root/data/db_backup.dump
echo "Database 'alliancemine' restored from /root/data/db_backup.dump"
# Step 6: Retrieve the secrets file from AWS Secrets Manager
echo "Step 6: Retrieving the secrets file from AWS Secrets Manager"
aws secretsmanager get-secret-value --region=us-east-1 --secret-id IntermineStagePropertiesFile --query SecretString --output text > alliancemine.properties
echo "Secrets file retrieved and saved to alliancemine.properties"
# Step 7: Append Solr URLs to the configuration files
echo "Step 7: Appending Solr URLs to the configuration files"
echo "index.solrurl=http://agr.stage.alliancemine.solr.server:8983/solr/alliancemine-search" >> dbmodel/resources/keyword_search.properties
echo "Solr URL for index search appended to dbmodel/resources/keyword_search.properties"
echo "autocomplete.solrurl=http://agr.stage.alliancemine.solr.server:8983/solr/alliancemine-autocomplete" >> dbmodel/resources/objectstoresummary.config.properties
echo "Solr URL for autocomplete appended to dbmodel/resources/objectstoresummary.config.properties"
# Step 8: Run the Solr load script
echo "Step 8: Running the Solr load script"
./build_solr postgres postgres
echo "Solr load script executed"
# Step 9: Deploy the application to Tomcat using Gradle
echo "Step 9: Deploying the application to Tomcat using Gradle"
./gradlew cargoRedeployRemote --stacktrace
echo "Application deployed to Tomcat"
# Step 10: Install Python dependencies
echo "Step 10: Installing Python dependencies"
# Ensure requirements for pip and python3-dev are installed.
apk add --no-cache python3-dev py3-pip build-base libffi-dev musl-dev
# Install pip packages
pip install --upgrade pip wheel
pip install intermine
pip install simplejson
pip install requests
pip install pandas
echo "Python dependencies installed"
# Step 11: Run the Python script with the environment flag
echo "Step 11: Running Python script to populate lists"
python3 recreatepubliclistsinalliance.py $ENV_FLAG
echo "Python script recreatepubliclistsinalliance.py executed with $ENV_FLAG"