-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_from_icp.sh
executable file
·95 lines (70 loc) · 2.45 KB
/
copy_from_icp.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#Set namespace to migrate
config=/home/ubuntu/.kube/config_icp
namespace=prod-mt
mkdir pvc_files_icp deployment_files_icp pre_deployment_icp
#Get all yaml file of n4j pods and copy data locally
for pod in `kubectl --kubeconfig=$config --namespace=$namespace get pods -o=name | grep icp | sed "s/^.\{4\}//"`
do
kubectl --kubeconfig=$config get -o=name deployment --namespace=$namespace | grep icp | sed "s/^.\{22\}//" > pvc_icp.txt
#kubectl cp "${pod}":/data data/$pod/. && kubectl get pods --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'
done
#Create PVC.yaml for each n4j pod
cat pvc_icp.txt | \
while read pvc; do
touch pvc_files_icp/$pvc.yaml
echo "
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
name: "$pvc"
namespace: "$namespace"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
storageClassName: standard
" >> pvc_files_icp/$pvc.yaml
echo "
apiVersion: apps/v1
kind: Deployment
metadata:
name: $pvc
labels:
app: $pvc
spec:
selector:
matchLabels:
app: $pvc
template:
metadata:
labels:
app: $pvc
spec:
containers:
- name: ubuntu
image: ubuntu:14.04
args: [bash, -c, 'for ((i = 0; ; i++)); do echo "$i: $(date)"; sleep 100; done']
volumeMounts:
- name: pgsql-persistent-storage
mountPath: /var/lib/postgresql/data
volumes:
- name: pgsql-persistent-storage
persistentVolumeClaim:
claimName: $pvc
" >> pre_deployment_icp/$pvc.yaml
done
#Get deployment yaml file of neo4j and find and replace PVC configuration
# make sure you use --export for all get to yaml bits or it will break the sed beloy potentially
for deployment in $(kubectl --kubeconfig=$config get -o=name deployment --namespace=$namespace | grep icp | sed "s/^.\{22\}//")
do
kubectl --kubeconfig=$config get -o=yaml deployment.extensions/$deployment --namespace=$namespace --export > deployment_files_icp/$deployment.yaml
# sed -zi 's!hostPath:\n.*path:.*/localdata/icp/'$namespace'/'$deployment'\n.*name: neo4j-data!name: neo4j-data\n persistentVolumeClaim:\n claimName: '$deployment'\n!g' deployment_files/$deployment.yaml
done
#for n in $(kubectl --kubeconfig=$config get -o=name --namespace=$namespace configmap,secret)
#do
# mkdir -p $(dirname $n)
# kubectl --kubeconfig=$config --namespace=$namespace get -o=yaml --export $n > $n.yaml
#done