-
Notifications
You must be signed in to change notification settings - Fork 0
/
del-snap.sh
executable file
·73 lines (38 loc) · 1.49 KB
/
del-snap.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
############## Author - Muhammad Irfan Tahir ###################
############# Displays Running Droplets and there specific snapshots
############# Then Removes the snapshot of each droplet with Number seven retention
#!/bin/bash
echo "Running droplets - "
doctl compute droplet list
mapfile -t IDLIST < <(doctl compute droplet list --format 'ID' --no-header)
for each in "${IDLIST[@]}"
do
echo "Droplet ID $each Number of Snap Shots"
doctl compute droplet snapshots $each
snapshot=$(doctl compute droplet snapshots $each --format "ID" --no-header | wc -l)
echo "Total Number Snapshot -"
echo "$snapshot"
finished=false
while ! $finished; do
if [ "$snapshot" -gt 7 ]; then
mapfile -t IDLIST1 < <(doctl compute droplet snapshots $each --format "ID" --no-header)
OLDEST=${IDLIST1[0]}
echo "Deleting SnapShot ID- $OLDEST"
#doctl compute image delete "$OLDEST" --force
doctl compute snapshot delete $OLDEST --force
sleep 15
fi
snapshot=0
doctl compute droplet snapshots $each #--format "ID" --no-header
snapshot=$(doctl compute droplet snapshots $each --format "ID" --no-header | wc -l)
echo "Remaining Snapshot Number - $snapshot"
if [ "$snapshot" -eq 7 ]; then
echo "Snapshot Number $snapshot is equal to retention"
finished=true
fi
if [ "$snapshot" -lt 7 ]; then
echo "Snapshot Number $snapshot is already under retention"
finished=true
fi
done
done