未验证 提交 0a5c8a1f 编写于 作者: D Davies Liu 提交者: GitHub

cmd/dump: dump metadata into STDOUT (#551)

* dump metadata into STDOUT

* update docs
上级 100aea23
...@@ -17,6 +17,7 @@ package main ...@@ -17,6 +17,7 @@ package main
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"github.com/juicedata/juicefs/pkg/meta" "github.com/juicedata/juicefs/pkg/meta"
...@@ -25,16 +26,21 @@ import ( ...@@ -25,16 +26,21 @@ import (
func dump(ctx *cli.Context) error { func dump(ctx *cli.Context) error {
setLoggerLevel(ctx) setLoggerLevel(ctx)
if ctx.Args().Len() < 2 { if ctx.Args().Len() < 1 {
return fmt.Errorf("META-ADDR and FILE are needed") return fmt.Errorf("META-ADDR is needed")
} }
m := meta.NewClient(ctx.Args().Get(0), &meta.Config{Retries: 10, Strict: true, Subdir: ctx.String("subdir")}) var fp io.WriteCloser
fname := ctx.Args().Get(1) if ctx.Args().Len() == 1 {
fp, err := os.OpenFile(fname, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) fp = os.Stdout
if err != nil { } else {
return err var err error
fp, err = os.OpenFile(ctx.Args().Get(1), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer fp.Close()
} }
defer fp.Close() m := meta.NewClient(ctx.Args().Get(0), &meta.Config{Retries: 10, Strict: true, Subdir: ctx.String("subdir")})
return m.DumpMeta(fp) return m.DumpMeta(fp)
} }
...@@ -42,7 +48,7 @@ func dumpFlags() *cli.Command { ...@@ -42,7 +48,7 @@ func dumpFlags() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "dump", Name: "dump",
Usage: "dump metadata into a JSON file", Usage: "dump metadata into a JSON file",
ArgsUsage: "META-ADDR FILE", ArgsUsage: "META-ADDR [FILE]",
Action: dump, Action: dump,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
......
...@@ -18,6 +18,7 @@ package main ...@@ -18,6 +18,7 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"github.com/juicedata/juicefs/pkg/meta" "github.com/juicedata/juicefs/pkg/meta"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
...@@ -25,15 +26,20 @@ import ( ...@@ -25,15 +26,20 @@ import (
func load(ctx *cli.Context) error { func load(ctx *cli.Context) error {
setLoggerLevel(ctx) setLoggerLevel(ctx)
if ctx.Args().Len() < 2 { if ctx.Args().Len() < 1 {
return fmt.Errorf("META-ADDR and FILE are needed") return fmt.Errorf("META-ADDR is needed")
}
var buf []byte
var err error
if ctx.Args().Len() == 1 {
buf, err = ioutil.ReadAll(os.Stdin)
} else {
buf, err = ioutil.ReadFile(ctx.Args().Get(1))
} }
m := meta.NewClient(ctx.Args().Get(0), &meta.Config{Retries: 10, Strict: true})
fname := ctx.Args().Get(1)
buf, err := ioutil.ReadFile(fname)
if err != nil { if err != nil {
return err return err
} }
m := meta.NewClient(ctx.Args().Get(0), &meta.Config{Retries: 10, Strict: true})
return m.LoadMeta(buf) return m.LoadMeta(buf)
} }
...@@ -41,7 +47,7 @@ func loadFlags() *cli.Command { ...@@ -41,7 +47,7 @@ func loadFlags() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "load", Name: "load",
Usage: "load metadata from a previously dumped JSON file", Usage: "load metadata from a previously dumped JSON file",
ArgsUsage: "META-ADDR FILE", ArgsUsage: "META-ADDR [FILE]",
Action: load, Action: load,
} }
} }
...@@ -525,9 +525,11 @@ dump metadata into a JSON file ...@@ -525,9 +525,11 @@ dump metadata into a JSON file
#### Synopsis #### Synopsis
``` ```
juicefs dump [command options] META-ADDR FILE juicefs dump [command options] META-ADDR [FILE]
``` ```
When the FILE is not provided, STDOUT will be used instead.
#### Options #### Options
`--subdir value`\ `--subdir value`\
...@@ -542,5 +544,7 @@ load metadata from a previously dumped JSON file ...@@ -542,5 +544,7 @@ load metadata from a previously dumped JSON file
#### Synopsis #### Synopsis
``` ```
juicefs load [command options] META-ADDR FILE juicefs load [command options] META-ADDR [FILE]
``` ```
When the FILE is not provided, STDIN will be used instead.
...@@ -525,9 +525,11 @@ juicefs warmup [command options] [PATH ...] ...@@ -525,9 +525,11 @@ juicefs warmup [command options] [PATH ...]
#### 使用 #### 使用
``` ```
juicefs dump [command options] META-ADDR FILE juicefs dump [command options] META-ADDR [FILE]
``` ```
如果没有指定导出文件路径,会导出到标准输出。
#### 选项 #### 选项
`--subdir value`\ `--subdir value`\
...@@ -542,5 +544,7 @@ juicefs dump [command options] META-ADDR FILE ...@@ -542,5 +544,7 @@ juicefs dump [command options] META-ADDR FILE
#### 使用 #### 使用
``` ```
juicefs load [command options] META-ADDR FILE juicefs load [command options] META-ADDR [FILE]
``` ```
如果没有指定导入文件路径,会从标准输入导入。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册