-
Notifications
You must be signed in to change notification settings - Fork 19
/
glacierabort
executable file
·112 lines (95 loc) · 2.56 KB
/
glacierabort
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
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
set -e
# Debug
# set -x
########
# Parse command line options
########
function print_usage {
echo "usage: glacierabort -v|--vault <vault> [-p|--profile <profile>]"
echo ""
echo "Abort all active multipart uploads to a vault on AWS glacier."
echo ""
echo " --vault name of the vault on AWS glacier"
echo " --profile optional profile name to use. The profile"
echo " name must be configured with the AWS CLI client."
echo " --help print this message"
}
arg_positional=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
print_usage
exit 0
;;
-p|--profile)
arg_profile="$2"
shift # past argument
shift # past value
;;
-v|--vault)
arg_vault="$2"
shift # past argument
shift # past value
;;
*) # unknown option
arg_positional+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${arg_positional[@]}" # restore positional parameters
if [ -z "$arg_vault" ]; then
echo "No vault specified!"
print_usage
exit 1
fi
readonly vault="$arg_vault"
readonly profile="${arg_profile:-}"
########
# Close uploads
########
echo ""
echo "Closing active uploads:"
# Result of > aws glacier list-multipart-uploads
# {
# "UploadsList": [
# {
# "MultipartUploadId": "RPI2Y4chvSaw1r19wVP717hghGEIV07i6WicIoNRj-6C1WBhSzAT4FRf-g0hGm8JvKWBE-vlSvTolospe9c-TCCViv_H",
# ...
# "VaultARN": "arn:aws:glacier:eu-west-1:190631152724:vaults/test"
# },
# {
# "MultipartUploadId": "BwqY0NTHjTX6bI8s8YlF0l2on9GYOwpXKO1L4RLEl0Bf5hrPBd9XB29zra1di3lLE6Mi5WU-ouTcDEWCqdjpqBb5d7lK",
# ...
# "VaultARN": "arn:aws:glacier:eu-west-1:190631152724:vaults/test"
# }
# ]
# }
list_args=()
if [[ -n "$profile" ]]; then
list_args+=('--profile')
list_args+=("$profile")
fi
list_args+=('glacier' 'list-multipart-uploads')
list_args+=('--account-id' '-')
list_args+=('--vault-name')
list_args+=("$vault")
list_args+=('--output' 'text')
list_args+=('--query' 'UploadsList[*].MultipartUploadId')
abort_args=()
if [[ -n "$profile" ]]; then
abort_args+=('--profile')
abort_args+=("$profile")
fi
abort_args+=('--account-id' '-')
abort_args+=('--vault-name')
abort_args+=('--output' 'json')
abort_args+=("$vault")
aws "${list_args[@]}" \
| tr '\t' '\n' \
| xargs -t -I {} aws glacier abort-multipart-upload --upload-id={} "${abort_args[@]}"
echo ""
echo "Remaining active uploads:"
aws "${list_args[@]}"