mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/backup: prevent from restoring to directory which is in use by VictoriaMetrics during the restore
This commit is contained in:
parent
5ae47e8940
commit
9d1ee1e2ae
2 changed files with 16 additions and 0 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/common"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/fslocal"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
)
|
||||
|
||||
|
@ -34,6 +35,16 @@ type Restore struct {
|
|||
func (r *Restore) Run() error {
|
||||
startTime := time.Now()
|
||||
|
||||
// Make sure VictoriaMetrics doesn't run during the restore process.
|
||||
if err := fs.MkdirAllIfNotExist(r.Dst.Dir); err != nil {
|
||||
return fmt.Errorf("cannot create dir %q: %s", r.Dst.Dir, err)
|
||||
}
|
||||
flockF, err := fs.CreateFlockFile(r.Dst.Dir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create lock file in %q; make sure VictoriaMetrics doesn't use the dir; error: %s", r.Dst.Dir, err)
|
||||
}
|
||||
defer fs.MustClose(flockF)
|
||||
|
||||
concurrency := r.Concurrency
|
||||
src := r.Src
|
||||
dst := r.Dst
|
||||
|
|
|
@ -72,6 +72,11 @@ func appendFilesInternal(dst []string, d *os.File) ([]string, error) {
|
|||
if name == "." || name == ".." {
|
||||
continue
|
||||
}
|
||||
if name == "flock.lock" {
|
||||
// Do not take into account flock.lock files, since they are used
|
||||
// for preventing from concurrent access.
|
||||
continue
|
||||
}
|
||||
path := dir + "/" + name
|
||||
if fi.IsDir() {
|
||||
// Process directory
|
||||
|
|
Loading…
Reference in a new issue