未验证 提交 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
import (
"fmt"
"io"
"os"
"github.com/juicedata/juicefs/pkg/meta"
......@@ -25,16 +26,21 @@ import (
func dump(ctx *cli.Context) error {
setLoggerLevel(ctx)
if ctx.Args().Len() < 2 {
return fmt.Errorf("META-ADDR and FILE are needed")
if ctx.Args().Len() < 1 {
return fmt.Errorf("META-ADDR is needed")
}
m := meta.NewClient(ctx.Args().Get(0), &meta.Config{Retries: 10, Strict: true, Subdir: ctx.String("subdir")})
fname := ctx.Args().Get(1)
fp, err := os.OpenFile(fname, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
var fp io.WriteCloser
if ctx.Args().Len() == 1 {
fp = os.Stdout
} else {
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)
}
......@@ -42,7 +48,7 @@ func dumpFlags() *cli.Command {
return &cli.Command{
Name: "dump",
Usage: "dump metadata into a JSON file",
ArgsUsage: "META-ADDR FILE",
ArgsUsage: "META-ADDR [FILE]",
Action: dump,
Flags: []cli.Flag{
&cli.StringFlag{
......
......@@ -18,6 +18,7 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/juicedata/juicefs/pkg/meta"
"github.com/urfave/cli/v2"
......@@ -25,15 +26,20 @@ import (
func load(ctx *cli.Context) error {
setLoggerLevel(ctx)
if ctx.Args().Len() < 2 {
return fmt.Errorf("META-ADDR and FILE are needed")
if ctx.Args().Len() < 1 {
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 {
return err
}
m := meta.NewClient(ctx.Args().Get(0), &meta.Config{Retries: 10, Strict: true})
return m.LoadMeta(buf)
}
......@@ -41,7 +47,7 @@ func loadFlags() *cli.Command {
return &cli.Command{
Name: "load",
Usage: "load metadata from a previously dumped JSON file",
ArgsUsage: "META-ADDR FILE",
ArgsUsage: "META-ADDR [FILE]",
Action: load,
}
}
......@@ -525,9 +525,11 @@ dump metadata into a JSON file
#### 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
`--subdir value`\
......@@ -542,5 +544,7 @@ load metadata from a previously dumped JSON file
#### 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 ...]
#### 使用
```
juicefs dump [command options] META-ADDR FILE
juicefs dump [command options] META-ADDR [FILE]
```
如果没有指定导出文件路径,会导出到标准输出。
#### 选项
`--subdir value`\
......@@ -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.
先完成此消息的编辑!
想要评论请 注册