-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackup.sh
executable file
·79 lines (64 loc) · 2.87 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# backup openshift by Filipe Calo - [email protected]
# Global Configurations
#======================
set -e
BACKUP_DIR=/opt/redhat/backup-yaml
# in dev
#AWS_CMD=/usr/bin/aws
#TIME_STAMP=$(date +%Y-%m-%d_%H-%M)
######################
oc login -u cluster-admin -p $CLUSTER_PASSWORD `rosa describe cluster -c rocpah1 | grep API |awk '{print $3}'`
function get_secret {
oc get secret -n ${1} -o=yaml --field-selector type!=kubernetes.io/service-account-token | sed -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d'
}
function get_configmap {
oc get configmap -n ${1} -o=yaml | sed -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d'
}
function get_route {
oc get route -n ${1} -o=yaml | sed -e '/status:/,+2d' -e '/\- ip: \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/d' -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d'
}
function get_service {
oc get service -n ${1} -o=yaml | sed -e '/ownerReferences:/,+5d' -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d' -e '/clusterIP: \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/d'
}
function get_deployment {
oc get deployment -n ${1} -o=yaml | sed -e '/deployment\.kubernetes\.io\/revision: "[0-9]\+"/d' -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d' -e '/status:/,+18d'
}
function get_cronjob {
oc get cronjob -n ${1} -o=yaml | sed -e '/status:/,+1d' -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d'
}
function get_pvc {
oc get pvc -n ${1} -o=yaml | sed -e '/control\-plane\.alpha\.kubernetes\.io\/leader\:/d' -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d'
}
function get_pv {
for pvolume in `oc get pvc -n ${1} -o=custom-columns=:.spec.volumeName`
do
oc get pv -o=yaml --field-selector metadata.name=${pvolume} | sed -e '/resourceVersion: "[0-9]\+"/d' -e '/selfLink: [a-z0-9A-Z/]\+/d'
done
}
function get_project {
oc get project |grep teste | awk '{print "oc get project "$1 " -o yaml > "}'
}
function export_ns {
mkdir -p ${BACKUP_DIR}/${CLUSTER_NAME}/
cd ${BACKUP_DIR}/${CLUSTER_NAME}/
for namespace in `oc get namespaces --no-headers=true | awk '{ print $1 }' | grep -e "cea-"`
do
echo "Namespace: $namespace"
echo "+++++++++++++++++++++++++"
mkdir -p $namespace
for object_kind in configmap route service secret deployment cronjob pvc
do
if oc get ${object_kind} -n ${namespace} 2>&1 | grep "No resources" > /dev/null; then
echo "No resources found for ${object_kind} in ${namespace}"
else
get_${object_kind} ${namespace} > ${namespace}/${object_kind}.${namespace}.yaml && echo "${object_kind}.${namespace}";
if [ ${object_kind} = "pvc" ]; then
get_pv ${namespace} > ${namespace}/pv.${namespace}.yaml && echo "pv.${namespace}";
fi
fi
done
echo "+++++++++++++++++++++++++"
done
}
export_ns