Skip to content

Commit

Permalink
create latest stable dump for upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Aug 24, 2023
1 parent a9f1079 commit 2b65b56
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/internal/database/meilisearch/meilisearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"go.uber.org/zap"
)

const (
dumpExtension = ".dump"
latestStableDumpExtension = ".latestdump"
)

// Meilisearch implements the database interface
type Meilisearch struct {
datadir string
Expand Down Expand Up @@ -124,6 +129,8 @@ func (db *Meilisearch) Upgrade() error {
return nil
}

// moveDumpsToBackupDir move all dumps to the backupdir
// also create a stable last stable dump for later upgrades
func (db *Meilisearch) moveDumpsToBackupDir() error {
dumpDir := path.Join(db.datadir, "dumps")
return filepath.Walk(dumpDir, func(basepath string, d fs.FileInfo, err error) error {
Expand All @@ -134,14 +141,21 @@ func (db *Meilisearch) moveDumpsToBackupDir() error {
return nil
}

if !strings.HasSuffix(d.Name(), ".dump") {
if !strings.HasSuffix(d.Name(), dumpExtension) {
return nil
}

dst := path.Join(constants.BackupDir, d.Name())
src := basepath
db.log.Infow("move dump", "from", src, "to", dst)

latestStableDst := path.Join(constants.BackupDir, strings.ReplaceAll(d.Name(), dumpExtension, latestStableDumpExtension))
db.log.Infow("create latest dump", "from", src, "to", latestStableDst)
err = utils.Copy(src, latestStableDst)
if err != nil {
return fmt.Errorf("unable create latest stable dump: %w", err)
}

copy := exec.Command("mv", "-v", src, dst)
copy.Stdout = os.Stdout
copy.Stderr = os.Stderr
Expand Down

0 comments on commit 2b65b56

Please sign in to comment.