internal/component => internal/dis/component

This commit is contained in:
Tom Wiesing 2022-10-18 09:40:37 +02:00
parent 9443217441
commit b5b1ce2340
No known key found for this signature in database
123 changed files with 76 additions and 76 deletions

View file

@ -0,0 +1,44 @@
package triplestore
import (
"encoding/json"
"io"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
)
func (ts *Triplestore) BackupName() string { return "triplestore" }
// Backup makes a backup of all Triplestore repositories databases into the path dest.
func (ts *Triplestore) Backup(context component.StagingContext) error {
// list all the directories
repos, err := ts.listRepositories()
if err != nil {
return err
}
// then backup each file separatly
return context.AddDirectory("", func() error {
for _, repo := range repos {
if err := context.AddFile(repo.ID+".nq", func(file io.Writer) error {
_, err := ts.SnapshotDB(file, repo.ID)
return err
}); err != nil {
return err
}
}
return nil
})
}
func (ts Triplestore) listRepositories() (repos []Repository, err error) {
res, err := ts.OpenRaw("GET", "/rest/repositories", nil, "", "application/json")
if err != nil {
return nil, err
}
defer res.Body.Close()
err = json.NewDecoder(res.Body).Decode(&repos)
return
}