Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VER=2.4
14 changes: 14 additions & 0 deletions app/femr/business/helpers/RollbackHelpers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package femr.business.helpers;

import java.io.IOException;

public class RollbackHelpers {
public static void backUpSQL() {
try {
String[] cmd = new String[]{"/bin/sh", "/app/util/backup/backup.sh"};
Process pr = Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
}
}
15 changes: 13 additions & 2 deletions app/femr/business/services/system/UpdatesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ public ServiceResponse<List<? extends IDatabaseStatus>> updateDatabaseStatuses()
ServiceResponse<List<? extends IDatabaseStatus>> response = new ServiceResponse<>();
//TODO: Do some more robust error checking
String[] cmd = new String[]{"/bin/bash", "femr.sh"};
String workingDir = System.getProperty("user.dir");
File dir = new File(workingDir, "app/femr/util/backup");
File dir = getScriptDirectory();
try {
Process pr = Runtime.getRuntime().exec(cmd, null, dir);
} catch (Exception e) {
Expand All @@ -142,6 +141,18 @@ public ServiceResponse<List<? extends IDatabaseStatus>> updateDatabaseStatuses()
return response;
}

private File getScriptDirectory(){
File dir = null;
try {
String workingDir = System.getProperty("user.dir");
dir = new File(workingDir, "app/femr/util/backup");
} catch (Exception e){
e.printStackTrace();
}
return dir;

}


}

11 changes: 11 additions & 0 deletions app/femr/ui/controllers/admin/UpdatesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,15 @@ public Result kitUpdatePost() {
return manageGet();
}

public Result rollbackPost() {
this.messages = new ArrayList<>();

// TODO run the rollback script here
// TODO need to check errors

messages.add("The rollback was successfully administered.");

return manageGet();
}

}
6 changes: 6 additions & 0 deletions app/femr/ui/views/admin/updates/manage.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ <h2>Available Updates __________</h2>
}
} else {<td>Kit Update: Already up to date</td>}
</tr>
<tr>
@helper.form(action = UpdatesController.rollbackPost()) {
<td>Data Rollback: Available</td><td>
<input type="submit" class="updateButton" value="Rollback"/></td>
}
</tr>

</table>

Expand Down
30 changes: 30 additions & 0 deletions app/femr/util/backup/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Values... adjust as needed or move around
ROOTDIR=../../../../
now=$(date +"%m_%d_%Y")
MYSQL_HOST='localhost'
MYSQL_PORT='3306'
MYSQL_USER='root'
MYSQL_PASSWORD='password'
DATABASE_NAME='femr_db'


# Creates a backup of the existing MySQL database
. $ROOTDIR/VERSION

mkdir -p $ROOTDIR/sqlbackups

# Backing up local database. REQUIRES VERSION FILE
mysqldump -h ${MYSQL_HOST} \
-P ${MYSQL_PORT} \
-u ${MYSQL_USER} \
-p${MYSQL_PASSWORD} \
${DATABASE_NAME} | gzip > $ROOTDIR/sqlbackups/$now-femr_backup-$VER.sql.gz
# mysqldump \
# --databases femr \
# --master-data=2 \
# --single-transaction \
# --order-by-primary \
# -r $now-rollbackBackupVer-$VER.sql
# Compress backup file to conserve resources.
31 changes: 11 additions & 20 deletions app/femr/util/backup/femr.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#!/bin/bash
# Creates a backup of the existing MySQL database and pushes it to a centralized Amazon RDS database.
#Backing up local database.
mysqldump \
--databases femr \
--master-data=2 \
--single-transaction \
--order-by-primary \
-r backup.sql
#Compress backup file to conserve network resources.
gzip backup.sql
#Transfer backup file to Amazon EC2 instance.
scp -r -i femrtest.pem backup.sql.gz [email protected]://home/ec2-user/test
#AWS command that unzips backup file and utilizes sed to remove definer information to prevent errors.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"commands":["gzip -d backup.sql.gz","sed '"'"'s/\\sDEFINER=`[^`]*`@`[^`]*`//g'"'"' -i backup.sql"],"workingDirectory":["/home/ec2-user/test"],"executionTimeout":["3600"]}' --comment "Unzips the backup file." --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Generates a authentication token and pushes backup file from EC2 instance to Amazon RDS database.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"commands":["RDSHOST=\"central.ccc42svxvmzp.us-east-2.rds.amazonaws.com\"","TOKEN=\"$(aws rds generate-db-auth-token --hostname $RDSHOST --port 3306 --region us-east-2 --username yash)\"","","mysql --host=$RDSHOST --port=3306 --ssl-ca=rds-ca-2019-root.pem --user=yash --password=$TOKEN < test/backup.sql"],"workingDirectory":["/home/ec2-user/"],"executionTimeout":["3600"]}' --comment "Pushes backup to master database. " --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Cleans up remaining files on EC2 instance.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"workingDirectory":["/home/ec2-user/test"],"executionTimeout":["3600"],"commands":["mv backup.sql old_backup.sql"]}' --comment "Cleans up." --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Removes leftover archive files. TODO: Move them to a different folder to store backup history.
rm backup.sql.gz
gzip backup.sql
#Transfer backup file to Amazon EC2 instance.
scp -r -i femrtest.pem backup.sql.gz [email protected]://home/ec2-user/test
#AWS command that unzips backup file and utilizes sed to remove definer information to prevent errors.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"commands":["gzip -d backup.sql.gz","sed '"'"'s/\\sDEFINER=`[^`]*`@`[^`]*`//g'"'"' -i backup.sql"],"workingDirectory":["/home/ec2-user/test"],"executionTimeout":["3600"]}' --comment "Unzips the backup file." --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Generates a authentication token and pushes backup file from EC2 instance to Amazon RDS database.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"commands":["RDSHOST=\"central.ccc42svxvmzp.us-east-2.rds.amazonaws.com\"","TOKEN=\"$(aws rds generate-db-auth-token --hostname $RDSHOST --port 3306 --region us-east-2 --username yash)\"","","mysql --host=$RDSHOST --port=3306 --ssl-ca=rds-ca-2019-root.pem --user=yash --password=$TOKEN < test/backup.sql"],"workingDirectory":["/home/ec2-user/"],"executionTimeout":["3600"]}' --comment "Pushes backup to master database. " --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Cleans up remaining files on EC2 instance.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"workingDirectory":["/home/ec2-user/test"],"executionTimeout":["3600"],"commands":["mv backup.sql old_backup.sql"]}' --comment "Cleans up." --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Removes leftover archive files. TODO: Move them to a different folder to store backup history.
rm backup.sql.gz
21 changes: 21 additions & 0 deletions app/femr/util/backup/oldfemr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# Creates a backup of the existing MySQL database and pushes it to a centralized Amazon RDS database.
#Backing up local database.
mysqldump \
--databases femr \
--master-data=2 \
--single-transaction \
--order-by-primary \
-r backup.sql
#Compress backup file to conserve network resources.
gzip backup.sql
#Transfer backup file to Amazon EC2 instance.
scp -r -i femrtest.pem backup.sql.gz [email protected]://home/ec2-user/test
#AWS command that unzips backup file and utilizes sed to remove definer information to prevent errors.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"commands":["gzip -d backup.sql.gz","sed '"'"'s/\\sDEFINER=`[^`]*`@`[^`]*`//g'"'"' -i backup.sql"],"workingDirectory":["/home/ec2-user/test"],"executionTimeout":["3600"]}' --comment "Unzips the backup file." --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Generates a authentication token and pushes backup file from EC2 instance to Amazon RDS database.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"commands":["RDSHOST=\"central.ccc42svxvmzp.us-east-2.rds.amazonaws.com\"","TOKEN=\"$(aws rds generate-db-auth-token --hostname $RDSHOST --port 3306 --region us-east-2 --username yash)\"","","mysql --host=$RDSHOST --port=3306 --ssl-ca=rds-ca-2019-root.pem --user=yash --password=$TOKEN < test/backup.sql"],"workingDirectory":["/home/ec2-user/"],"executionTimeout":["3600"]}' --comment "Pushes backup to master database. " --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Cleans up remaining files on EC2 instance.
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-06c56ec70246c0870"]}]' --parameters '{"workingDirectory":["/home/ec2-user/test"],"executionTimeout":["3600"],"commands":["mv backup.sql old_backup.sql"]}' --comment "Cleans up." --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchOutputEnabled":true}' --region us-east-2
#Removes leftover archive files. TODO: Move them to a different folder to store backup history.
rm backup.sql.gz
8 changes: 4 additions & 4 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ default.admin.username="admin"
default.admin.password="admin"

#Default superuser username and password
default.superuser.username="superuser"
default.superuser.password="superuser"
default.superuser.username=""
default.superuser.password=""

#Set to 1 to limit functionality to only the research module
#Set to 0 (or not 1) for normal functionality
Expand All @@ -21,8 +21,8 @@ play.il8n.langs="en"

#Register MySQL database settings
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost/femr_db?characterEncoding=UTF-8"
db.default.username="sa"
db.default.url="jdbc:mysql://localhost/femr?characterEncoding=UTF-8"
db.default.username=""
db.default.password=""
db.default.logStatements=false

Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GET /admin/configure @femr.ui.controll
POST /admin/configure @femr.ui.controllers.admin.ConfigureController.managePost()
GET /admin/updates @femr.ui.controllers.admin.UpdatesController.manageGet()
POST /admin/updates/database @femr.ui.controllers.admin.UpdatesController.databasePost()
POST /admin/updates/rollback @femr.ui.controllers.admin.UpdatesController.rollbackPost()
POST /admin/updates/kit @femr.ui.controllers.admin.UpdatesController.kitUpdatePost()
GET /admin/trips @femr.ui.controllers.admin.TripController.manageGet()
POST /admin/trips @femr.ui.controllers.admin.TripController.managePost()
Expand Down