-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
62 lines (50 loc) · 1.67 KB
/
backup.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
# installing required tools
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# backing up namespaced resource
for n in $(kubectl get ns -o=name)
do
dirlist+=("$n")
done
for i in ${dirlist[@]}
do
echo $i
mkdir -p $i
q=$( echo $i | sed s/"namespace\/"// )
echo 'getting resource from namespace' $q
for d in $(kubectl api-resources --namespaced=true -o=name)
do
mkdir -p $i/$d
for y in $(kubectl get $d -n $q -o=name)
do
echo 'getting resource' $y
v=$(echo $y | sed s/".*\/"// | sed s/"\/"//)
kubectl get $d $v -n $q -o=yaml > ./$i/$d/$v.yaml
done
done
done
# backing up default namespaced resource
i=default-namespaced-resources
mkdir -p $i
for d in $(kubectl api-resources --namespaced=false -o=name)
do
mkdir -p $i/$d
echo $d
for y in $(kubectl get $d -o=name)
do
echo 'getting resource' $y
v=$(echo $y | sed s/".*\/"// | sed s/"\/"//)
# echo kubectl get $d $v -n $q -o=yaml
kubectl get $d $v -o=yaml > ./$i/$d/$v.yaml
# kubectl get $d -n $q -o=yaml > $i/$d/$d.yaml
done
done
# ziping the folders
zipname=$(echo "k8s-manifest-backup-$(date +"%Y-%m-%d-%H-%M-%S").zip")
zip -r $zipname ./namespace ./non-namespaced-resources
# copying backup zip to s3 bucket
aws s3 cp $zipname s3://tardis-ai-pipelines/manifest-backup/$zipname