@@ -105,13 +105,59 @@ POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=false
105105
106106curl "http://localhost:9200/_snapshot/s3-backup/mp-2020.11.02/_restore?wait_for_completion=false" -H "Content-type: application/json" -d'
107107{
108- "indices": "mp-2020.11.01",
109- "ignore_unavailable": true,
110- "include_global_state": false,
111- "rename_pattern": "(.+)",
112- "rename_replacement": "restored_$1",
113- "include_aliases": false
108+ "indices": "boris,filebeat-2020.10.10", "ignore_unavailable": true, "include_global_state": false, "rename_pattern": "(.+)", "rename_replacement": "restored_$1", "include_aliases": false
114109}'
115110
111+ curl -ks https://opendistro:9200/_cat/indices/restored*?health=green
112+
113+ for _, iname := range request.Values.Indices {
114+ ind := snap_status.Snapshots[0].Indices[iname]
115+
116+ if ind.ShardsStats.Total == 1 {
117+ if ind.Stats.Total.Size < rt.nodes.max {
118+
119+ req := map[string]interface{}{
120+ "ignore_unavailable": false,
121+ "include_global_state": false,
122+ "include_aliases": false,
123+ "rename_pattern": "(.+)",
124+ "rename_replacement": "restored_$1",
125+ "indices": request.Values.Indices,
126+ "index_settings": map[string]interface{}{"index.number_of_replicas": 0},
127+ }
128+
129+ response, err := rt.doPost(rt.conf.Elastic.Host+"_snapshot/"+request.Values.Repo+"/"+request.Values.Snapshot+"/_restore?wait_for_completion=false", req)
130+ if err != nil {
131+ http.Error(w, err.Error(), 500)
132+ log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", 500, "\t", err.Error(), "\t", r.UserAgent())
133+ return
134+ }
135+ w.Write(response)
136+
137+ } else {
138+ msg := fmt.Sprintf("{\"error\":\"Restore index '%s' failed with: Not enough space\"}", iname)
139+ http.Error(w, msg, 600)
140+ log.Println(request.Action, "\t", 600, "\t", "Restore index '", iname, "' failed with: not enough space")
141+ return
142+ }
143+ } else { // индексы с snapshots >1 - пока восстанавливаем без проверок
144+ req := map[string]interface{}{
145+ "ignore_unavailable": false,
146+ "include_global_state": false,
147+ "include_aliases": false,
148+ "rename_pattern": "(.+)",
149+ "rename_replacement": "restored_$1",
150+ "indices": request.Values.Indices,
151+ "index_settings": map[string]interface{}{"index.number_of_replicas": 0},
152+ }
116153
154+ response, err := rt.doPost(rt.conf.Elastic.Host+"_snapshot/"+request.Values.Repo+"/"+request.Values.Snapshot+"/_restore?wait_for_completion=false", req)
155+ if err != nil {
156+ http.Error(w, err.Error(), 500)
157+ log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", 500, "\t", err.Error(), "\t", r.UserAgent())
158+ return
159+ }
160+ w.Write(response)
161+ }
117162
163+ } // end for
0 commit comments