github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/buildscripts/heal-manual.go (about) 1 //go:build ignore 2 // +build ignore 3 4 // 5 // MinIO Object Storage (c) 2022 MinIO, Inc. 6 // 7 // Licensed under the Apache License, Version 2.0 (the "License"); 8 // you may not use this file except in compliance with the License. 9 // You may obtain a copy of the License at 10 // 11 // http://www.apache.org/licenses/LICENSE-2.0 12 // 13 // Unless required by applicable law or agreed to in writing, software 14 // distributed under the License is distributed on an "AS IS" BASIS, 15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 // See the License for the specific language governing permissions and 17 // limitations under the License. 18 // 19 20 package main 21 22 import ( 23 "context" 24 "encoding/json" 25 "fmt" 26 "log" 27 "os" 28 "time" 29 30 "github.com/minio/madmin-go/v3" 31 ) 32 33 func main() { 34 // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY are 35 // dummy values, please replace them with original values. 36 37 // API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise. 38 // New returns an MinIO Admin client object. 39 madmClnt, err := madmin.New(os.Args[1], os.Args[2], os.Args[3], false) 40 if err != nil { 41 log.Fatalln(err) 42 } 43 44 opts := madmin.HealOpts{ 45 Recursive: true, // recursively heal all objects at 'prefix' 46 Remove: true, // remove content that has lost quorum and not recoverable 47 ScanMode: madmin.HealNormalScan, // by default do not do 'deep' scanning 48 } 49 50 start, _, err := madmClnt.Heal(context.Background(), "healing-rewrite-bucket", "", opts, "", false, false) 51 if err != nil { 52 log.Fatalln(err) 53 } 54 fmt.Println("Healstart sequence ===") 55 enc := json.NewEncoder(os.Stdout) 56 if err = enc.Encode(&start); err != nil { 57 log.Fatalln(err) 58 } 59 60 fmt.Println() 61 for { 62 _, status, err := madmClnt.Heal(context.Background(), "healing-rewrite-bucket", "", opts, start.ClientToken, false, false) 63 if status.Summary == "finished" { 64 fmt.Println("Healstatus on items ===") 65 for _, item := range status.Items { 66 if err = enc.Encode(&item); err != nil { 67 log.Fatalln(err) 68 } 69 } 70 break 71 } 72 if status.Summary == "stopped" { 73 fmt.Println("Healstatus on items ===") 74 fmt.Println("Heal failed with", status.FailureDetail) 75 break 76 } 77 78 for _, item := range status.Items { 79 if err = enc.Encode(&item); err != nil { 80 log.Fatalln(err) 81 } 82 } 83 84 time.Sleep(time.Second) 85 } 86 }