-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpull.sh
More file actions
70 lines (59 loc) · 1.56 KB
/
Copy pathpull.sh
File metadata and controls
70 lines (59 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Script to pull storage from remote server
REMOVE=false
ONLY_STATS=false
BASE_DIRECTORY="\$SCRATCH"
ARGS=""
while [ $# -gt 0 ]
do
while getopts i:b:ds flag
do
case "${flag}" in
i) ID="${OPTARG}";;
b) BASE_DIRECTORY="${OPTARG}";;
d) REMOVE=true;;
s) ONLY_STATS=true;;
\?) echo "Invalid option -$OPTARG" >&2;;
esac
done
shift $((OPTIND-1))
ARGS="${ARGS} $1 "
shift
done
POSARGS=($ARGS)
HOST=${POSARGS[0]}
BASE_DIRECTORY=$(ssh $HOST echo $BASE_DIRECTORY)
if [ -z ${BASE_DIRECTORY} ]; then
echo "Could not connect to host."
exit 1
fi
echo "PULLING $ID"
echo "FROM $BASE_DIRECTORY"
if [ "$REMOVE" = true ]; then
echo "Deleting existing storage zip file."
ssh daint "rm $BASE_DIRECTORY/storage.zip"
fi
# zip on server and pull
if [ -z ${ID} ]; then
echo "Zipping entire storage."
ZIP_COMMAND="zip -ur $BASE_DIRECTORY/storage.zip $BASE_DIRECTORY/ -x $BASE_DIRECTORY/experience/\* "
if [ "$ONLY_STATS" = true ]; then
ZIP_COMMAND="$ZIP_COMMAND -x $BASE_DIRECTORY/saved_models/\*"
fi
else
echo "Updating/Adding $ID to zip file."
ZIP_COMMAND="zip -ur $BASE_DIRECTORY/storage.zip $BASE_DIRECTORY/experiments/$ID/ "
if [ "$ONLY_STATS" = false ]; then
ZIP_COMMAND="$ZIP_COMMAND $BASE_DIRECTORY/saved_models/$ID/"
fi
fi
echo $ZIP_COMMAND
# execute and download
ssh $HOST $ZIP_COMMAND
scp $HOST:$BASE_DIRECTORY/storage.zip .
unzip -o storage.zip -d storage/
cp -r storage/$BASE_DIRECTORY/* storage/
# cleanup
IFS="/" read -a PATH_ARRAY <<< "$BASE_DIRECTORY"
rm -r storage/${PATH_ARRAY[1]}
rm storage.zip