-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor load_mongodump.sh script #150
Changes from 8 commits
6a46d8e
df28c81
20a2c6f
3a156c1
f36706a
00e0347
79618e8
960b449
9b90990
1da7854
82dfe2e
ce28e3e
8d25f43
fea748b
458e0f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ services: | |
depends_on: | ||
- db | ||
environment: | ||
- DB_HOST=db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be helpful to make these same changes in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intent of using
Please let me know what you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thought was that the updated default with the formatting might make it easier to switch that dataset in use when editing the docker file (ie update from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify, users don't need to rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverting back to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, I don't understand why you reverted this change. I am also not sure how it works, given that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have documented my testing below #150 (comment)
I understand, it would assign I have also re-done testing and updated detailed logs below. #150 (comment) |
||
- DB_HOST=mongodb://db/DB_NAME | ||
- WEB_SERVER_HOST=0.0.0.0 | ||
- CRON_MODE= | ||
- STUDY_CONFIG=stage-program | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,71 @@ | ||
#!/bin/bash | ||
|
||
# Directory of the script | ||
SCRIPT_DIR="$(dirname "$0")" | ||
|
||
# Path to the configuration file (one level up) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should be two levels up |
||
CONFIG_FILE="$SCRIPT_DIR/../../docker-compose.dev.yml" | ||
|
||
# Check if the correct number of arguments is provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <mongodump-file>" | ||
echo " <mongodump-file> : The path to the MongoDB dump file to be restored." | ||
echo " run git add -f <docker compose file> after using this command" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this since it contradicts the README instructions. I know it was in the original PR, but was removed in response to review feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iantei the entire if check does not contradict the README, only the last There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have re-introduced the check while removing the last |
||
exit 1 | ||
fi | ||
|
||
MONGODUMP_FILE=$1 | ||
|
||
echo "Copying file to docker container" | ||
docker cp $MONGODUMP_FILE em-public-dashboard-db-1:/tmp | ||
# Print debug information | ||
echo "Script Directory: $SCRIPT_DIR" | ||
echo "Configuration File Path: $CONFIG_FILE" | ||
echo "MongoDump File Path: $MONGODUMP_FILE" | ||
|
||
# Check if the provided file exists | ||
if [ ! -f "$MONGODUMP_FILE" ]; then | ||
echo "Error: File '$MONGODUMP_FILE' does not exist." | ||
exit 1 | ||
fi | ||
|
||
# Check if the configuration file exists | ||
if [ ! -f "$CONFIG_FILE" ]; then | ||
echo "Error: Configuration file '$CONFIG_FILE' does not exist." | ||
exit 1 | ||
fi | ||
|
||
# Print details about the configuration file | ||
echo "Configuration file details:" | ||
ls -l "$CONFIG_FILE" | ||
|
||
# Extract the database name from the mongodump file | ||
DB_NAME=$(tar -tf "$MONGODUMP_FILE" | grep '^dump/' | sed 's|^dump/||' | awk -F'/' '{if (NF > 0) {print $1; exit}}') | ||
|
||
# Output the database name | ||
echo "$DB_NAME" | ||
|
||
if [ -z "$DB_NAME" ]; then | ||
echo "Error: Failed to extract database name from mongodump." | ||
exit 1 | ||
fi | ||
|
||
echo "Database Name: $DB_NAME" | ||
|
||
# Update the docker-compose configuration file with the actual DB_HOST | ||
DB_HOST="mongodb://db/$DB_NAME" | ||
sed -i.bak "s|DB_HOST:.*|DB_HOST: $DB_HOST|" "$CONFIG_FILE" | ||
|
||
echo "Updated docker-compose file:" | ||
cat "$CONFIG_FILE" | ||
|
||
echo "Copying file to Docker container" | ||
docker cp "$MONGODUMP_FILE" em-public-dashboard-db-1:/tmp | ||
|
||
FILE_NAME=$(basename "$MONGODUMP_FILE") | ||
|
||
echo "Clearing existing database" | ||
docker exec em-public-dashboard-db-1 bash -c "mongo $DB_NAME --eval 'db.dropDatabase()'" | ||
|
||
FILE_NAME=`basename $MONGODUMP_FILE` | ||
echo "Restoring the dump from $FILE_NAME to database $DB_NAME" | ||
docker exec -e MONGODUMP_FILE=$FILE_NAME em-public-dashboard-db-1 bash -c "cd /tmp && tar xvf $FILE_NAME && mongorestore -d $DB_NAME dump/$DB_NAME" | ||
|
||
echo "Restoring the dump from $FILE_NAME" | ||
docker exec -e MONGODUMP_FILE=$FILE_NAME em-public-dashboard-db-1 bash -c 'cd /tmp && tar xvf $MONGODUMP_FILE && mongorestore' | ||
echo "Database restore complete." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you get rid of this extra line please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I have removed the comment