Skip to content

Commit

Permalink
Add a script to save the contents of the students home directories (i…
Browse files Browse the repository at this point in the history
…novex#8)

* Add a script to save the contents of the students home directories

* Add docs

* scp in parallel for better network utilization

Add output to gitignore
  • Loading branch information
hikhvar authored and johscheuer committed Jul 27, 2019
1 parent b08b048 commit 0faf282
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ terraform.tfstate.backup
.terraform
ips
packages
homes
account.json
.DS_STORE
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ Now we can verify everything with the `plan` step: `terraform plan` if everythin
## Clean up

In order to clean up everything just run: `terraform destroy`

### Save Homes

If you want to save the homes for your students, run the script `save_homes.sh`. This will copy all the contents of `/home/student` from the machines onto your machine. Then zip the files up and place them in `$(pwd)/homes`.
33 changes: 33 additions & 0 deletions save_homes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -eu

# Find the script location. Inspired by: https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself
scriptLocation="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

dest=${scriptLocation}/homes
mkdir -p ${dest}

function ipOf() {
local student=${1}
local node=${2}
cat ${scriptLocation}/ips/${student} | grep ${node} | awk '{ print $2 }'
}

function download() {
local student=${1}
tmpDir=$(mktemp -d)
mkdir ${tmpDir}/master
scp -q -o StrictHostKeyChecking=no -r -i ${scriptLocation}/keys/${student} student@$(ipOf ${student} master):/home/student ${tmpDir}/master || echo "some files might be missing for ${student} master"
mkdir ${tmpDir}/node
scp -q -o StrictHostKeyChecking=no -r -i ${scriptLocation}/keys/${student} student@$(ipOf ${student} node):/home/student ${tmpDir}/node || echo "some files might be missing for ${student} node"
zip -q -r ${dest}/${student}_home.zip ${tmpDir}
rm -rf ${tmpDir}
}

for student in $(find ips -type f -exec basename {} \;) ;
do
download ${student} &
done

wait

0 comments on commit 0faf282

Please sign in to comment.