github.com/weaviate/weaviate@v1.24.6/modules/backup-filesystem/module.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package modstgfs 13 14 import ( 15 "context" 16 "net/http" 17 "os" 18 "path" 19 "path/filepath" 20 21 "github.com/pkg/errors" 22 "github.com/sirupsen/logrus" 23 "github.com/weaviate/weaviate/entities/modulecapabilities" 24 "github.com/weaviate/weaviate/entities/moduletools" 25 ) 26 27 const ( 28 Name = "backup-filesystem" 29 AltName1 = "filesystem" 30 backupsPathName = "BACKUP_FILESYSTEM_PATH" 31 ) 32 33 type Module struct { 34 logger logrus.FieldLogger 35 dataPath string // path to the current (operational) data 36 backupsPath string // complete(?) path to the directory that holds all the backups 37 } 38 39 func New() *Module { 40 return &Module{} 41 } 42 43 func (m *Module) Name() string { 44 return Name 45 } 46 47 func (m *Module) IsExternal() bool { 48 return false 49 } 50 51 func (m *Module) AltNames() []string { 52 return []string{AltName1} 53 } 54 55 func (m *Module) Type() modulecapabilities.ModuleType { 56 return modulecapabilities.Backup 57 } 58 59 func (m *Module) Init(ctx context.Context, 60 params moduletools.ModuleInitParams, 61 ) error { 62 m.logger = params.GetLogger() 63 m.dataPath = params.GetStorageProvider().DataPath() 64 backupsPath := os.Getenv(backupsPathName) 65 if err := m.initBackupBackend(ctx, backupsPath); err != nil { 66 return errors.Wrap(err, "init backup backend") 67 } 68 69 return nil 70 } 71 72 func (m *Module) HomeDir(backupID string) string { 73 return path.Join(m.makeBackupDirPath(backupID)) 74 } 75 76 func (m *Module) RootHandler() http.Handler { 77 // TODO: remove once this is a capability interface 78 return nil 79 } 80 81 func (m *Module) MetaInfo() (map[string]interface{}, error) { 82 metaInfo := make(map[string]interface{}) 83 metaInfo["backupsPath"] = m.backupsPath 84 return metaInfo, nil 85 } 86 87 func (m *Module) makeBackupDirPath(id string) string { 88 return filepath.Join(m.backupsPath, id) 89 } 90 91 // verify we implement the modules.Module interface 92 var ( 93 _ = modulecapabilities.Module(New()) 94 _ = modulecapabilities.BackupBackend(New()) 95 _ = modulecapabilities.MetaProvider(New()) 96 )