mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-19 15:30:17 +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/common"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/fslocal"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/fslocal"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,6 +35,16 @@ type Restore struct {
|
||||||
func (r *Restore) Run() error {
|
func (r *Restore) Run() error {
|
||||||
startTime := time.Now()
|
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
|
concurrency := r.Concurrency
|
||||||
src := r.Src
|
src := r.Src
|
||||||
dst := r.Dst
|
dst := r.Dst
|
||||||
|
|
|
@ -72,6 +72,11 @@ func appendFilesInternal(dst []string, d *os.File) ([]string, error) {
|
||||||
if name == "." || name == ".." {
|
if name == "." || name == ".." {
|
||||||
continue
|
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
|
path := dir + "/" + name
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
// Process directory
|
// Process directory
|
||||||
|
|
Loading…
Reference in a new issue