|
4 | 4 | # call Primary Pod and start basebackup |
5 | 5 | count=0 |
6 | 6 | while true ; do |
7 | | - hostName=$(kubectl get pods -l cluster-name=acid-cluster-1,spilo-role=master -o go-template --template '{{range .items}}{{.metadata.name}} {{ break }}{{end}}') |
8 | | - if [ -z "$hostName" ] |
9 | | - then |
| 7 | + hostName=$(kubectl get pods -l cluster-name=${SCOPE},spilo-role=master -o go-template --template '{{range .items}}{{.metadata.name}} {{ break }}{{end}}') |
| 8 | + if [ -z "$hostName" ]; then |
10 | 9 | sleep 5 |
11 | 10 | output_info "pgBackRest: waiting for primary-Pod" |
| 11 | + ((count++)) |
| 12 | + if [ "$count" == 30 ]; then |
| 13 | + output_error "pgBackRest: waiting for primary-Pod - Timeout - Skip Step" |
| 14 | + skip=1 |
| 15 | + break |
| 16 | + fi |
12 | 17 | else |
13 | 18 | break |
14 | 19 | fi |
15 | 20 | done |
16 | | -output_info "pgBackRest: Detect Primary-Pod $hostName" |
17 | | -while true ; do |
18 | | - unset error |
19 | | - kubectl exec $hostName -c postgres -- /bin/bash -c 'pgbackrest backup --type=full --stanza=db --repo=1' || { output_error "pgBackRest: Create basebackup failed"; error=true; } |
20 | | - if [ "$error" = true ]; then |
21 | | - sleep 5 |
22 | | - else |
23 | | - break; |
24 | | - fi |
25 | | -done |
| 21 | +count=0 |
| 22 | +if [ "$skip" == 1 ]; then |
| 23 | + output_error "pgBackRest: No primary pod found - prevent deadlock and start database" |
| 24 | +else |
| 25 | + output_info "pgBackRest: Detect Primary-Pod $hostName" |
| 26 | + while true ; do |
| 27 | + unset error |
| 28 | + kubectl exec $hostName -c postgres -- /bin/bash -c 'pgbackrest backup --type=full --stanza=db --repo=1' || { output_error "pgBackRest: Create basebackup failed"; error=true; } |
| 29 | + if [ "$error" = true ]; then |
| 30 | + if [ "$count" == 3 ]; then |
| 31 | + output_error "pgBackRest: Basebackup could not be created. Abort init-script"; |
| 32 | + exit 0 |
| 33 | + else |
| 34 | + ((count++)) |
| 35 | + sleep 5 |
| 36 | + fi |
| 37 | + else |
| 38 | + break; |
| 39 | + fi |
| 40 | + done |
| 41 | + |
| 42 | + output_info "pgBackRest: Update Restore-Configmap" |
| 43 | + configmap="${SCOPE}-pgbackrest-restore" |
| 44 | + kubectl get cm $configmap -o yaml | \ |
| 45 | + sed -e 's|restore_basebackup: "false"|restore_basebackup: "true"|' | \ |
| 46 | + kubectl apply -f - |
26 | 47 |
|
27 | | -output_info "pgBackRest: Update Restore-Configmap" |
28 | | -configmap="${SCOPE}-pgbackrest-restore" |
29 | | -kubectl get cm $configmap -o yaml | \ |
30 | | - sed -e 's|restore_basebackup: "false"|restore_basebackup: "true"|' | \ |
31 | | - kubectl apply -f - |
| 48 | + output_info "pgBackRest: Backup complete" |
| 49 | +fi |
32 | 50 |
|
33 | | -output_info "pgBackRest: Backup complete" |
|
0 commit comments