diff --git a/cmd/dump.go b/cmd/dump.go index 4518b03ea6a5..e15bc5cf075b 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -18,10 +18,12 @@ package cmd import ( "compress/gzip" + "errors" "io" "os" "strings" + "github.com/DataDog/zstd" "github.com/juicedata/juicefs/pkg/meta" "github.com/urfave/cli/v2" ) @@ -78,15 +80,12 @@ func dumpMeta(m meta.Meta, dst string, threads int, keepSecret, fast, skipTrash w = os.Stdout } else { tmp := dst + ".tmp" - fp, e := os.OpenFile(tmp, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) + fp, e := os.Create(tmp) if e != nil { return e } defer func() { - e := fp.Close() - if err == nil { - err = e - } + err = errors.Join(err, fp.Close()) if err == nil { err = os.Rename(tmp, dst) } else { @@ -95,14 +94,15 @@ func dumpMeta(m meta.Meta, dst string, threads int, keepSecret, fast, skipTrash }() if strings.HasSuffix(dst, ".gz") { - zw := gzip.NewWriter(fp) + w, _ = gzip.NewWriterLevel(fp, gzip.BestSpeed) + defer func() { + err = errors.Join(err, w.Close()) + }() + } else if strings.HasSuffix(dst, ".zstd") { + w = zstd.NewWriterLevel(fp, zstd.BestSpeed) defer func() { - e := zw.Close() - if err == nil { - err = e - } + err = errors.Join(err, w.Close()) }() - w = zw } else { w = fp } diff --git a/pkg/vfs/backup.go b/pkg/vfs/backup.go index 6f2221ed5a0e..27582134fba2 100644 --- a/pkg/vfs/backup.go +++ b/pkg/vfs/backup.go @@ -98,7 +98,7 @@ func backup(m meta.Meta, blob object.ObjectStorage, now time.Time, fast, skipTra } defer os.Remove(fp.Name()) defer fp.Close() - zw := gzip.NewWriter(fp) + zw, _ := gzip.NewWriterLevel(fp, gzip.BestSpeed) var threads = 2 if m.Name() == "tikv" { threads = 10