-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path008-restore
More file actions
executable file
·69 lines (49 loc) · 2.21 KB
/
008-restore
File metadata and controls
executable file
·69 lines (49 loc) · 2.21 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
auth 2>/dev/null || authn 2>/dev/null
# Updates records based on list of UUIDs
#
tenant=$(cat tenant)
okapi_url=$(cat okapi.url)
okapi_token=$(cat okapi.token)
batchsize=6
infile=uuids
outfile="srs_update_log.json"
rm -f ${outfile}
if [[ ${1} =~ ^[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*$ ]];then echo "${1}" > uuids;fi
if [[ ! -f ${infile} ]]; then echo "This script cannot find input file ${infile}";exit;fi
numrecs=$(wc -l ${infile} |cut -d " " -f1)
fixrecord() {
local uuid=${1}
local seq=${2}
local new008
local updated_record
local apicall
apicall=$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/source-storage/records/${uuid}/formatted?idType=INSTANCE" |jq .)
new008=$(echo "${apicall}" | jq -r '.rawRecord.content |fromjson |.fields[] |select(."008" != null) | ."008"')
uuid=$(echo ${apicall} |jq -r .id)
updated_record=$(echo "${apicall}" |jq -r --arg VALUE "${new008}" '
# ((.parsedRecord.content.fields[] | select(."008" != null) |."008") = "780615s19uu xx a eng d")
((.parsedRecord.content.fields[] | select(."008" != null) |."008") = $VALUE)
|del(.metadata)
')
apicall=$(curl --http1.1 -s -w '\n' -X PUT -H "Content-type: application/json" -H "Accept: text/plain" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" -d "${updated_record}" "${okapi_url}/source-storage/records/${uuid}")
echo "${apicall}" |grep -i [a-z] >> "tmp_records.${fileno}"
}
counter=0
SECONDS=1
while mapfile -t -n ${batchsize} lines && ((${#lines[@]})); do
seq=0
for uuid in "${lines[@]}";do
fixrecord "${uuid}" "${seq}"
counter=$(($counter + 1))
seq=$(($seq + 1))
done
wait
TIME=$SECONDS;msg="$SECONDS seconds"
if [[ $SECONDS -gt 60 ]];then TIME=$(bc <<< "scale=1;$SECONDS/60");msg="$TIME minutes";fi
if [[ $SECONDS -gt 3600 ]];then TIME=$(bc <<< "scale=1;$SECONDS/3600");msg="$TIME hours ";fi
echo -en "Processing record $counter of $numrecs in $msg\r"
cat tmp_records.* >> ${outfile}
rm tmp_records.*
done < ${infile}
echo "Finished processing $numrecs ${recordtype} records in $msg"
echo "Output was sent to ${outfile}"