-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
backupNowDisabledJob.sh
99 lines (84 loc) · 3.13 KB
/
backupNowDisabledJob.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
cluster='mycluster'
username='myusername'
password='mypassword'
domain='mydomain.net'
jobname='MyJob'
keeplocalfor=5
# authenticate
auth=$(curl -X POST -k \
--url "https://${cluster}/irisservices/api/v1/public/accessTokens" \
-H 'Accept: application/json' \
-H 'Content-type: application/json' -d '{
"password": "'${password}'",
"username": "'${username}'",
"domain": "'${domain}'"
}' 2>/dev/null)
token=$(echo $auth | sed "s/.*\"accessToken\":\"\([^\"]*\).*/\1/")
# find job
job=$(curl -X GET -k \
--url "https://${cluster}/irisservices/api/v1/public/protectionJobs?names=${jobname}" \
-H 'Content-type: application/json' \
-H "authorization: Bearer ${token}" 2>/dev/null)
job="xxbeginxx${job}xxendxx"
job=$(echo $job | sed "s/xxbeginxx\[//g")
job=$(echo $job | sed "s/\]xxendxx//g")
jobid=$(echo $job | sed "s/.*\"id\":\([0-9]*\).*/\1/g")
# get last job run ID
run=$(curl -X GET -k \
--url "https://${cluster}/irisservices/api/v1/public/protectionRuns?jobId=${jobid}&numRuns=1" \
-H 'Content-type: application/json' \
-H "authorization: Bearer ${token}" 2>/dev/null)
lastRunId=$(echo $run | sed "s/.*\"jobRunId\":\([0-9]*\).*/\1/g")
newRunId=$lastRunId
# enable job
enable=$(curl -X POST -k \
--url "https://${cluster}/irisservices/api/v1/public/protectionJobState/${jobid}" \
-H 'Content-type: application/json' \
-H "authorization: Bearer ${token}" \
-d '{"pause": false, "pauseReason": 0}' 2>/dev/null)
sleep 3
# run job
echo "running ${jobname} (${jobid})..."
curl -X POST -k \
--url "https://${cluster}/irisservices/api/v1/public/protectionJobs/run/${jobid}" \
-H 'Content-type: application/json' \
-H "authorization: Bearer ${token}" \
-d '{
"runType": "kRegular",
"copyRunTargets":[
{
"type": "kLocal",
"daysToKeep": '${keeplocalfor}'
}
]
}'
# wait for new run to appear
while [ $newRunId -eq $lastRunId ]
do
run=$(curl -X GET -k \
--url "https://${cluster}/irisservices/api/v1/public/protectionRuns?jobId=${jobid}&numRuns=1" \
-H 'Content-type: application/json' \
-H "authorization: Bearer ${token}" 2>/dev/null)
newRunId=$(echo $run | sed "s/.*\"jobRunId\":\([0-9]*\).*/\1/g")
sleep 1
done
# wait for job run to finish
status="kRunning"
finishedStates=(kCanceled kSuccess kFailure)
while [[ ! " ${finishedStates[@]} " =~ " ${status} " ]]
do
sleep 1
run=$(curl -X GET -k \
--url "https://${cluster}/irisservices/api/v1/public/protectionRuns?jobId=${jobid}&numRuns=1" \
-H 'Content-type: application/json' \
-H "authorization: Bearer ${token}" 2>/dev/null)
status=$(echo $run | sed "s/.*\"status\":\"\([^\"]*\).*/\1/g")
done
echo "Status: $status"
# disable job
enable=$(curl -X POST -k \
--url "https://${cluster}/irisservices/api/v1/public/protectionJobState/${jobid}" \
-H 'Content-type: application/json' \
-H "authorization: Bearer ${token}" \
-d '{"pause": true, "pauseReason": 0}' 2>/dev/null)