github.com/minio/madmin-go/v3@v3.0.51/examples/heal-manual.go (about) 1 //go:build ignore 2 // +build ignore 3 4 // Copyright (c) 2015-2022 MinIO, Inc. 5 // 6 // This file is part of MinIO Object Storage stack 7 // 8 // This program is free software: you can redistribute it and/or modify 9 // it under the terms of the GNU Affero General Public License as 10 // published by the Free Software Foundation, either version 3 of the 11 // License, or (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU Affero General Public License for more details. 17 // 18 // You should have received a copy of the GNU Affero General Public License 19 // along with this program. If not, see <http://www.gnu.org/licenses/>. 20 // 21 22 package main 23 24 import ( 25 "context" 26 "encoding/json" 27 "fmt" 28 "log" 29 "os" 30 "time" 31 32 "github.com/minio/madmin-go/v3" 33 ) 34 35 func main() { 36 // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY are 37 // dummy values, please replace them with original values. 38 39 // API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise. 40 // New returns an MinIO Admin client object. 41 madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) 42 if err != nil { 43 log.Fatalln(err) 44 } 45 46 opts := madmin.HealOpts{ 47 Recursive: true, // recursively heal all objects at 'prefix' 48 Remove: true, // remove content that has lost quorum and not recoverable 49 Recreate: true, // rewrite all old non-inlined xl.meta to new xl.meta 50 ScanMode: madmin.HealNormalScan, // by default do not do 'deep' scanning 51 } 52 53 start, _, err := madmClnt.Heal(context.Background(), "healing-rewrite-bucket", "", opts, "", false, false) 54 if err != nil { 55 log.Fatalln(err) 56 } 57 fmt.Println("Healstart sequence ===") 58 enc := json.NewEncoder(os.Stdout) 59 if err = enc.Encode(&start); err != nil { 60 log.Fatalln(err) 61 } 62 63 fmt.Println() 64 for { 65 _, status, err := madmClnt.Heal(context.Background(), "healing-rewrite-bucket", "", opts, start.ClientToken, false, false) 66 if status.Summary == "finished" { 67 fmt.Println("Healstatus on items ===") 68 for _, item := range status.Items { 69 if err = enc.Encode(&item); err != nil { 70 log.Fatalln(err) 71 } 72 } 73 break 74 } 75 if status.Summary == "stopped" { 76 fmt.Println("Healstatus on items ===") 77 fmt.Println("Heal failed with", status.FailureDetail) 78 break 79 } 80 81 for _, item := range status.Items { 82 if err = enc.Encode(&item); err != nil { 83 log.Fatalln(err) 84 } 85 } 86 87 time.Sleep(time.Second) 88 } 89 }