-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s-backup.sh
27 lines (22 loc) · 887 Bytes
/
k8s-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
#!/bin/bash
# Get all kubernetes resources
datenow=$(date +'%d-%m-%Y')
pathToSave="/home/usefree/K8s-Backup-$datenow"
for namespace in dev default
do
for resource in pods statefulset service deployment secrets prometheusrules clusterroles rolebinding
do
if [ ! -d $pathToSave/$namespace/$resource ]; then
echo "Creating $pathToSave/$namespace/$resource"
mkdir -p $pathToSave/$namespace/$resource
fi
for file in $(kubectl get $resource -n $namespace | awk '{print$1}' | cut -d / -f2 | grep -v NAME);
do
echo "Writing file $file.yaml to $pathToSave/$namespace/$resource/";
kubectl get $resource $file -n $namespace -o yaml > $pathToSave/$namespace/$resource/$file.yaml;
done;
done;
done;
cd ../$pathToSave
tar -cvf k8sBackup-$datenow.tar $pathToSave
echo "All jobs finished."