From 2ddf41e309291ef2121c7b0062116cf2e44feb94 Mon Sep 17 00:00:00 2001 From: Yash Satyavarpu Date: Mon, 31 May 2021 19:58:33 -0700 Subject: [PATCH 01/10] New function to get script directory --- .../business/services/system/UpdatesService.java | 15 +++++++++++++-- conf/application.conf | 10 +++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/femr/business/services/system/UpdatesService.java b/app/femr/business/services/system/UpdatesService.java index 72e7addd..b5b2db8b 100644 --- a/app/femr/business/services/system/UpdatesService.java +++ b/app/femr/business/services/system/UpdatesService.java @@ -124,8 +124,7 @@ public ServiceResponse> updateDatabaseStatuses() ServiceResponse> 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) { @@ -142,6 +141,18 @@ public ServiceResponse> 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; + + } + } diff --git a/conf/application.conf b/conf/application.conf index 726192ef..a5625d63 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -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="root" +default.superuser.password="Sc1ent1st" #Set to 1 to limit functionality to only the research module #Set to 0 (or not 1) for normal functionality @@ -21,9 +21,9 @@ 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.password="" +db.default.url="jdbc:mysql://localhost/femr?characterEncoding=UTF-8" +db.default.username="root" +db.default.password="Sc1ent1st" db.default.logStatements=false #Register paths for photos From bf932e89738360cf2cc18318dc08c972369c0fb0 Mon Sep 17 00:00:00 2001 From: siriwans <35212476+siriwans@users.noreply.github.com> Date: Mon, 31 May 2021 20:11:58 -0700 Subject: [PATCH 02/10] rollback button --- app/femr/ui/views/admin/updates/manage.scala.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/femr/ui/views/admin/updates/manage.scala.html b/app/femr/ui/views/admin/updates/manage.scala.html index 83fa2064..db256ae1 100644 --- a/app/femr/ui/views/admin/updates/manage.scala.html +++ b/app/femr/ui/views/admin/updates/manage.scala.html @@ -62,6 +62,12 @@

Available Updates __________

} } else {Kit Update: Already up to date} + + @helper.form(action = UpdatesController.kitUpdatePost()) { + Data Rollback: Available + + } + From e4976f7a109e7e81606fa9f9aa307f2f807821fb Mon Sep 17 00:00:00 2001 From: Yash Satyavarpu Date: Mon, 31 May 2021 22:20:41 -0700 Subject: [PATCH 03/10] quick fix --- conf/application.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/application.conf b/conf/application.conf index a5625d63..575a3587 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -3,8 +3,8 @@ default.admin.username="admin" default.admin.password="admin" #Default superuser username and password -default.superuser.username="root" -default.superuser.password="Sc1ent1st" +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 @@ -22,8 +22,8 @@ play.il8n.langs="en" #Register MySQL database settings db.default.driver="com.mysql.jdbc.Driver" db.default.url="jdbc:mysql://localhost/femr?characterEncoding=UTF-8" -db.default.username="root" -db.default.password="Sc1ent1st" +db.default.username="" +db.default.password="" db.default.logStatements=false #Register paths for photos From e44a33a59e02de7c2d7f01202a8482124976ec38 Mon Sep 17 00:00:00 2001 From: Mirei Date: Mon, 31 May 2021 22:32:28 -0700 Subject: [PATCH 04/10] add rollback function --- app/femr/ui/controllers/admin/UpdatesController.java | 11 +++++++++++ app/femr/ui/views/admin/updates/manage.scala.html | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/femr/ui/controllers/admin/UpdatesController.java b/app/femr/ui/controllers/admin/UpdatesController.java index 1a268055..902a0889 100644 --- a/app/femr/ui/controllers/admin/UpdatesController.java +++ b/app/femr/ui/controllers/admin/UpdatesController.java @@ -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(); + } + } diff --git a/app/femr/ui/views/admin/updates/manage.scala.html b/app/femr/ui/views/admin/updates/manage.scala.html index db256ae1..06791008 100644 --- a/app/femr/ui/views/admin/updates/manage.scala.html +++ b/app/femr/ui/views/admin/updates/manage.scala.html @@ -63,7 +63,7 @@

Available Updates __________

} else {Kit Update: Already up to date} - @helper.form(action = UpdatesController.kitUpdatePost()) { + @helper.form(action = UpdatesController.rollbackPost()) { Data Rollback: Available } From 287d26c4df3a6faba84e46b36739770f07ca3c24 Mon Sep 17 00:00:00 2001 From: Yash Satyavarpu Date: Tue, 1 Jun 2021 00:20:48 -0700 Subject: [PATCH 05/10] Updated script for fEMR AWS account --- app/femr/util/backup/femr.pem | 27 +++++++++++++++++++++++++++ app/femr/util/backup/femr.sh | 8 ++++---- 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 app/femr/util/backup/femr.pem diff --git a/app/femr/util/backup/femr.pem b/app/femr/util/backup/femr.pem new file mode 100644 index 00000000..59dcc3ac --- /dev/null +++ b/app/femr/util/backup/femr.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA24JlGVgPkV9DWRy0b7AAAgHCv3Rlr8Y2mlUkQvwcC4cFQ09r +5Gs3hQs/ovk+FscSeyeQqnluBqgT8QwuJrL8qHhJ3nv6795wTsIfbisRYF+WoOZG +8SQSqTgguZiBggsrmebvUKetHV8wkoRqh3CMxsydoK9LALScZ2+FO2tpetxmjm+Q +nCCzm1J8mZqJuQ4ARZXt80h8y4QTKxCMJA6aygg29xoyUkwtkbXnx0rm/ietWqi6 +bG85hQL7wnuQo9HOCEgCDTqF8thIjoTFYEbsHBlSp3vGDTfqaLpNT7YAMB0w2n/v +2EG3xbpOj85GUGUlFJoz2lw9+THihD9LjLp+kwIDAQABAoIBADUJpZnhECnk5aXz +bJmL4gSaHk8aNbOp5emWZuOUfMZAQoJH/166lTidRiv/owPn58w//BFks7QCCod0 +lPYeyzN9lQOf2zr3+RTejK+W0mUB06he24dKWwPuHuIZOjmMr2VJSkunqAlvxZGx +UvgUtr8WE4QOtsWd3iiT5pI72smnYqYZckbRgAClHKaEscc4+FHTLQEPscXzyxT+ +CacPWw1ulYITlrJLAUlk2E4V//IGTZAyBpfmLELzoJLtY1hMNoWBz84mJf9BqAW/ +jaumV05bhjdigqxZtzwsvGaDE5KEiLL1MZjtA0nO8xjf69HbzxO7x5xVcqWeN7fW +JyfUbJECgYEA+GbnBw5AsJ9njkpuItnjxf/VZtkAByacsvGWYth/2XMjIoBNr2am +5vnwEZWP/KcwrNEOMMhLGvG2LiogB02HoTYWbUnxH/OwhC3KeRDHvLSGxgbXeh3w +L+MpV3yJUAOK58k9o9FlimgLEzxBxYbXysm5/3vbundJr/sisU9pausCgYEA4jlA +Ivz+FauhxY8XUM41y1LWzulRpRlkXDf4xMTXGXe4GudmBKDEJRKjQs2rXMy4HscC +8hyaZH6Tebq6hxhQTiEIi3/8Q7/BTETMagmwUQlGVIOoxhvcmTQzGmf7Q+E7mJFA +q9x2CExuRoAaoTBg5TArspS1RBm7Gl2PiCY0gPkCgYEApLSelWgW7sYThR7HHma5 +h+0V1Aco5JTurBxSaiJBy65zaooGeLopCthJHW+9NHqrZLuNnD0Cx8/jy4J1EEKR +HwzdHAQ+VMBhl5NBQLsmpXJSNvYMZFV7kFUgcXkLFznyHbSrIXdTy80nIs7+kXnS +lgziPowi6uXzvzNXEpikPpcCgYAMrNiDHVm/LRarUxEjXep1sfaHMVt5vKp64Ef3 +/m9u5d5S45Q7viY/TYQIQi3PzUijsNLhbejYqJ7quyOoXhxhxEgOSOWBhkT2WQR7 +DH/sinB+W8IhF36MtvgGCr1xWDVWnwzYlEmovV+QY60aSvOi48gPAXYGksqA960L +G9jlQQKBgQDh1RIVQLO5/AaHu9sNCqqwHh9F1CMeBJVDvCbRLLswm1rZsznaHE8o +xFWQImgAI8mYast9quXtJSXoe++qORenjtqrnqG5RDFaatb8KmcN/oBkRwdLwW6f +03+/FzG5juOTbz108x8DWtzyXaN8EFzKIy3Tdz/0PaOllqVhuPlEyQ== +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/app/femr/util/backup/femr.sh b/app/femr/util/backup/femr.sh index af09260c..4e533718 100755 --- a/app/femr/util/backup/femr.sh +++ b/app/femr/util/backup/femr.sh @@ -10,12 +10,12 @@ mysqldump \ #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 ec2-user@ec2-3-15-230-33.us-east-2.compute.amazonaws.com://home/ec2-user/test +scp -r -i femr.pem backup.sql.gz ec2-user@ec2-18-117-72-13.us-east-2.compute.amazonaws.com://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 +aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-05dd30ce8dbef71e6"]}]' --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 +aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-05dd30ce8dbef71e6"]}]' --parameters '{"commands":["RDSHOST=\"central.cg61tbpj3kut.us-east-2.rds.amazonaws.com\"","TOKEN=\"$(aws rds generate-db-auth-token --hostname $RDSHOST --port 3306 --region us-east-2 --username admin)\"","","mysql --host=$RDSHOST --port=3306 --ssl-ca=rds-ca-2019-root.pem --user=admin --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 +aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-05dd30ce8dbef71e6"]}]' --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 \ No newline at end of file From aace636299345a0b4e0e1ba0271c13423b137e8d Mon Sep 17 00:00:00 2001 From: ktran Date: Tue, 1 Jun 2021 01:14:29 -0700 Subject: [PATCH 06/10] added rollbackhelper+backup script --- VERSION | 1 + .../business/helpers/RollbackHelpers.java | 14 +++++++++ app/femr/util/backup/backup.sh | 30 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 VERSION create mode 100644 app/femr/business/helpers/RollbackHelpers.java create mode 100755 app/femr/util/backup/backup.sh diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..c22ea80b --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +VER=2.4 \ No newline at end of file diff --git a/app/femr/business/helpers/RollbackHelpers.java b/app/femr/business/helpers/RollbackHelpers.java new file mode 100644 index 00000000..3d5f7aab --- /dev/null +++ b/app/femr/business/helpers/RollbackHelpers.java @@ -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(); + } + } +} diff --git a/app/femr/util/backup/backup.sh b/app/femr/util/backup/backup.sh new file mode 100755 index 00000000..a553573e --- /dev/null +++ b/app/femr/util/backup/backup.sh @@ -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. From 14f33aee3f052ad7948ddc06a5f55cd1ac4a8859 Mon Sep 17 00:00:00 2001 From: ktran Date: Tue, 1 Jun 2021 01:29:26 -0700 Subject: [PATCH 07/10] bug fix-defect report --- app/femr/util/backup/backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/femr/util/backup/backup.sh b/app/femr/util/backup/backup.sh index a553573e..6c4851eb 100755 --- a/app/femr/util/backup/backup.sh +++ b/app/femr/util/backup/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash # Values... adjust as needed or move around -ROOTDIR=../../../ +ROOTDIR=../../../../ now=$(date +"%m_%d_%Y") MYSQL_HOST='localhost' MYSQL_PORT='3306' From b1a8fde6cd5295b6692623a6ebd6a155631e99a9 Mon Sep 17 00:00:00 2001 From: Yash Satyavarpu Date: Tue, 1 Jun 2021 02:29:00 -0700 Subject: [PATCH 08/10] Delete femr.pem deleted for security --- app/femr/util/backup/femr.pem | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 app/femr/util/backup/femr.pem diff --git a/app/femr/util/backup/femr.pem b/app/femr/util/backup/femr.pem deleted file mode 100644 index 59dcc3ac..00000000 --- a/app/femr/util/backup/femr.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA24JlGVgPkV9DWRy0b7AAAgHCv3Rlr8Y2mlUkQvwcC4cFQ09r -5Gs3hQs/ovk+FscSeyeQqnluBqgT8QwuJrL8qHhJ3nv6795wTsIfbisRYF+WoOZG -8SQSqTgguZiBggsrmebvUKetHV8wkoRqh3CMxsydoK9LALScZ2+FO2tpetxmjm+Q -nCCzm1J8mZqJuQ4ARZXt80h8y4QTKxCMJA6aygg29xoyUkwtkbXnx0rm/ietWqi6 -bG85hQL7wnuQo9HOCEgCDTqF8thIjoTFYEbsHBlSp3vGDTfqaLpNT7YAMB0w2n/v -2EG3xbpOj85GUGUlFJoz2lw9+THihD9LjLp+kwIDAQABAoIBADUJpZnhECnk5aXz -bJmL4gSaHk8aNbOp5emWZuOUfMZAQoJH/166lTidRiv/owPn58w//BFks7QCCod0 -lPYeyzN9lQOf2zr3+RTejK+W0mUB06he24dKWwPuHuIZOjmMr2VJSkunqAlvxZGx -UvgUtr8WE4QOtsWd3iiT5pI72smnYqYZckbRgAClHKaEscc4+FHTLQEPscXzyxT+ -CacPWw1ulYITlrJLAUlk2E4V//IGTZAyBpfmLELzoJLtY1hMNoWBz84mJf9BqAW/ -jaumV05bhjdigqxZtzwsvGaDE5KEiLL1MZjtA0nO8xjf69HbzxO7x5xVcqWeN7fW -JyfUbJECgYEA+GbnBw5AsJ9njkpuItnjxf/VZtkAByacsvGWYth/2XMjIoBNr2am -5vnwEZWP/KcwrNEOMMhLGvG2LiogB02HoTYWbUnxH/OwhC3KeRDHvLSGxgbXeh3w -L+MpV3yJUAOK58k9o9FlimgLEzxBxYbXysm5/3vbundJr/sisU9pausCgYEA4jlA -Ivz+FauhxY8XUM41y1LWzulRpRlkXDf4xMTXGXe4GudmBKDEJRKjQs2rXMy4HscC -8hyaZH6Tebq6hxhQTiEIi3/8Q7/BTETMagmwUQlGVIOoxhvcmTQzGmf7Q+E7mJFA -q9x2CExuRoAaoTBg5TArspS1RBm7Gl2PiCY0gPkCgYEApLSelWgW7sYThR7HHma5 -h+0V1Aco5JTurBxSaiJBy65zaooGeLopCthJHW+9NHqrZLuNnD0Cx8/jy4J1EEKR -HwzdHAQ+VMBhl5NBQLsmpXJSNvYMZFV7kFUgcXkLFznyHbSrIXdTy80nIs7+kXnS -lgziPowi6uXzvzNXEpikPpcCgYAMrNiDHVm/LRarUxEjXep1sfaHMVt5vKp64Ef3 -/m9u5d5S45Q7viY/TYQIQi3PzUijsNLhbejYqJ7quyOoXhxhxEgOSOWBhkT2WQR7 -DH/sinB+W8IhF36MtvgGCr1xWDVWnwzYlEmovV+QY60aSvOi48gPAXYGksqA960L -G9jlQQKBgQDh1RIVQLO5/AaHu9sNCqqwHh9F1CMeBJVDvCbRLLswm1rZsznaHE8o -xFWQImgAI8mYast9quXtJSXoe++qORenjtqrnqG5RDFaatb8KmcN/oBkRwdLwW6f -03+/FzG5juOTbz108x8DWtzyXaN8EFzKIy3Tdz/0PaOllqVhuPlEyQ== ------END RSA PRIVATE KEY----- \ No newline at end of file From d0531fe5d88e63ba63d889895ddcfcbb6dbc57b1 Mon Sep 17 00:00:00 2001 From: siriwans <35212476+siriwans@users.noreply.github.com> Date: Thu, 3 Jun 2021 18:18:04 -0700 Subject: [PATCH 09/10] added route for rollback button --- conf/routes | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/routes b/conf/routes index feb40d01..c7252fdf 100644 --- a/conf/routes +++ b/conf/routes @@ -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() From 0d8e25c5d4236af7a3a2b14ba162aba04604f213 Mon Sep 17 00:00:00 2001 From: Yash Satyavarpu Date: Wed, 23 Feb 2022 21:06:48 -0800 Subject: [PATCH 10/10] Added a check for internet connection before running --- .../ui/views/admin/updates/manage.scala.html | 2 +- app/femr/util/backup/femr.sh | 31 +++++++------------ app/femr/util/backup/oldfemr.sh | 21 +++++++++++++ 3 files changed, 33 insertions(+), 21 deletions(-) create mode 100755 app/femr/util/backup/oldfemr.sh diff --git a/app/femr/ui/views/admin/updates/manage.scala.html b/app/femr/ui/views/admin/updates/manage.scala.html index 06791008..e7858178 100644 --- a/app/femr/ui/views/admin/updates/manage.scala.html +++ b/app/femr/ui/views/admin/updates/manage.scala.html @@ -65,7 +65,7 @@

Available Updates __________

@helper.form(action = UpdatesController.rollbackPost()) { Data Rollback: Available - + } diff --git a/app/femr/util/backup/femr.sh b/app/femr/util/backup/femr.sh index 4e533718..9a4c1d51 100755 --- a/app/femr/util/backup/femr.sh +++ b/app/femr/util/backup/femr.sh @@ -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 femr.pem backup.sql.gz ec2-user@ec2-18-117-72-13.us-east-2.compute.amazonaws.com://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-05dd30ce8dbef71e6"]}]' --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-05dd30ce8dbef71e6"]}]' --parameters '{"commands":["RDSHOST=\"central.cg61tbpj3kut.us-east-2.rds.amazonaws.com\"","TOKEN=\"$(aws rds generate-db-auth-token --hostname $RDSHOST --port 3306 --region us-east-2 --username admin)\"","","mysql --host=$RDSHOST --port=3306 --ssl-ca=rds-ca-2019-root.pem --user=admin --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-05dd30ce8dbef71e6"]}]' --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 \ No newline at end of file + gzip backup.sql + #Transfer backup file to Amazon EC2 instance. + scp -r -i femrtest.pem backup.sql.gz ec2-user@ec2-3-15-230-33.us-east-2.compute.amazonaws.com://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 \ No newline at end of file diff --git a/app/femr/util/backup/oldfemr.sh b/app/femr/util/backup/oldfemr.sh new file mode 100755 index 00000000..af09260c --- /dev/null +++ b/app/femr/util/backup/oldfemr.sh @@ -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 ec2-user@ec2-3-15-230-33.us-east-2.compute.amazonaws.com://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 \ No newline at end of file