-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from opensafely-core/archive
feat: handle workspace archiving
- Loading branch information
Showing
6 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
workspace=$1 | ||
workspace_dir=$HIGH_PRIVACY_STORAGE_BASE/workspaces/$workspace | ||
archive=$HIGH_PRIVACY_STORAGE_BASE/archives/$workspace.tar.xz | ||
|
||
|
||
if ! test -d "$workspace_dir"; then | ||
if test -f "$archive"; then | ||
echo "$workspace is already archived at $archive" | ||
exit 1 | ||
else | ||
echo "Directory $workspace_dir does not exist" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
index=$(mktemp) | ||
tar --directory "$HIGH_PRIVACY_STORAGE_BASE/workspaces" --create --xz --verbose --file "$archive" "$workspace/" | tee "$index" | ||
|
||
|
||
# compare the list of files we expect to check that the tar seems good. | ||
if ! diff -u "$index" <(tar --list --file "$archive"); then | ||
echo "$archive does not contain the expected list of files!" | ||
echo "Exiting *without* deleting $workspace_dir" | ||
exit 1 | ||
fi | ||
|
||
read -p "$archive created. About to remove $workspace_dir directory. Are you sure? " -n 1 -r | ||
if test "$REPLY" != "y"; then | ||
echo "Not removing $workspace_dir" | ||
exit 1 | ||
fi | ||
echo | ||
|
||
rm -rf "$workspace_dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
HIGH_PRIVACY_STORAGE_BASE=$(mktemp -d) | ||
trap 'rm -rf $HIGH_PRIVACY_STORAGE_BASE' EXIT | ||
|
||
error () { | ||
echo "$@" | ||
exit 1 | ||
} | ||
|
||
mkdir -p "$HIGH_PRIVACY_STORAGE_BASE/archives" | ||
DIR="$HIGH_PRIVACY_STORAGE_BASE/workspaces/test-workspace" | ||
mkdir -p "$DIR" | ||
|
||
echo "foo" > "$HIGH_PRIVACY_STORAGE_BASE/workspaces/test-workspace/foo.txt" | ||
echo "bar,baz" > "$HIGH_PRIVACY_STORAGE_BASE/workspaces/test-workspace/bar.csv" | ||
|
||
export HIGH_PRIVACY_STORAGE_BASE | ||
|
||
EXPECTED_ARCHIVE="$HIGH_PRIVACY_STORAGE_BASE/archives/test-workspace.tar.xz" | ||
|
||
echo y | ./scripts/archive.sh test-workspace | ||
|
||
test -f "$EXPECTED_ARCHIVE" || error "Could not find $EXPECTED_ARCHIVE" | ||
test -d "$DIR" && error "$DIR still exists" | ||
|
||
echo y | ./scripts/unarchive.sh test-workspace | ||
|
||
test -f "$EXPECTED_ARCHIVE" && error "$EXPECTED_ARCHIVE still exists" | ||
test -d "$DIR" || error "$DIR does not exist" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
workspace=$1 | ||
workspace_dir=$HIGH_PRIVACY_STORAGE_BASE/workspaces/$workspace | ||
archive=$HIGH_PRIVACY_STORAGE_BASE/archives/$workspace.tar.xz | ||
|
||
|
||
if ! test -f "$archive"; then | ||
if test -d "$workspace_dir"; then | ||
echo "$workspace_dir already exists" | ||
exit 1 | ||
else | ||
echo "Archive file $archive does not exist" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
tar --directory "$HIGH_PRIVACY_STORAGE_BASE/workspaces" --extract --xz --verbose --file "$archive" | ||
|
||
read -p "$workspace_dir created from $archive. About to remove $archive. Are you sure? " -n 1 -r | ||
if test "$REPLY" != "y"; then | ||
echo "Not removing $archive" | ||
exit 1 | ||
fi | ||
echo | ||
|
||
rm -rf "$archive" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters