-
Notifications
You must be signed in to change notification settings - Fork 7
/
archive_folder.sh
71 lines (61 loc) · 1.96 KB
/
archive_folder.sh
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
71
#! /bin/bash -l
FOLDER=$1
if [[ "$(readlink -f $(dirname $FOLDER))" != "$(readlink -f $(pwd))" ]]
then
echo "Make sure that you are running the script from the folder containing $(basename $FOLDER)"
exit 1
fi
FOLDER="$(basename $FOLDER)"
PORT=20489
if [[ ! -e "$FOLDER" ]]
then
echo "$FOLDER does not exist"
exit 1
fi
echo " **** $FOLDER **** "
# create an archive folder with symlinks
echo "$(date) - curl -s -X POST -d '{\"remove\": \"False\"}' localhost:${PORT}/api/1.0/create_dir/$FOLDER"
resp=$(curl -s -X POST -d '{"remove": "False"}' localhost:${PORT}/api/1.0/create_dir/$FOLDER)
echo "$resp"
# calculate checksums
echo "$(date) - curl -s -X POST localhost:${PORT}/api/1.0/gen_checksums/${FOLDER}_archive"
resp="$(curl -s -X POST localhost:${PORT}/api/1.0/gen_checksums/${FOLDER}_archive)"
echo "$resp"
id=$(echo "$resp" |jq '.job_id')
state=$(echo "$resp" |jq '.state')
while [[ "$state" != "\"done\"" ]]
do
sleep 30
resp="$(curl -s localhost:${PORT}/api/1.0/status/$id)"
state=$(echo "$resp" |jq '.state')
echo "$(date) - curl -s localhost:${PORT}/api/1.0/status/$id - $state"
if [[ "$state" == "\"error\"" ]]
then
echo "$(date) - encountered error - exiting"
echo "Failed archiving $FOLDER"
echo " **** $FOLDER **** "
exit 1
fi
done
# upload to archive
echo "$(date) - curl -s -X POST localhost:${PORT}/api/1.0/upload/${FOLDER}_archive"
resp="$(curl -s -X POST localhost:${PORT}/api/1.0/upload/${FOLDER}_archive)"
echo "$resp"
id=$(echo "$resp" |jq '.job_id')
state=$(echo "$resp" |jq '.state')
while [[ "$state" != "\"done\"" ]]
do
sleep 60
resp="$(curl -s localhost:${PORT}/api/1.0/status/$id)"
state=$(echo "$resp" |jq '.state')
echo "$(date) - curl -s localhost:${PORT}/api/1.0/status/$id - $state"
if [[ "$state" == "\"error\"" ]]
then
echo "$(date) - encountered error - exiting"
echo "Failed archiving $FOLDER"
echo " **** $FOLDER **** "
exit 1
fi
done
echo "Successfully archived $FOLDER"
echo " **** $FOLDER **** "