load.go 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * JuiceFS, Copyright (C) 2021 Juicedata, Inc.
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package main

import (
	"fmt"
	"io/ioutil"
21
	"os"
22 23 24 25 26 27 28

	"github.com/juicedata/juicefs/pkg/meta"
	"github.com/urfave/cli/v2"
)

func load(ctx *cli.Context) error {
	setLoggerLevel(ctx)
29
	if ctx.Args().Len() < 1 {
30
		return fmt.Errorf("META-URL is needed")
31 32 33 34 35 36 37
	}
	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))
38 39 40 41
	}
	if err != nil {
		return err
	}
42
	m := meta.NewClient(ctx.Args().Get(0), &meta.Config{Retries: 10, Strict: true})
43 44 45 46 47 48
	return m.LoadMeta(buf)
}

func loadFlags() *cli.Command {
	return &cli.Command{
		Name:      "load",
S
Sandy Xu 已提交
49
		Usage:     "load metadata from a previously dumped JSON file",
50
		ArgsUsage: "META-URL [FILE]",
51 52 53
		Action:    load,
	}
}