github.com/m3db/m3@v1.5.0/src/cmd/tools/clone_fileset/main/main.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package main
    22  
    23  import (
    24  	"flag"
    25  	"log"
    26  	"os"
    27  
    28  	"github.com/m3db/m3/src/dbnode/persist/fs/clone"
    29  	xtime "github.com/m3db/m3/src/x/time"
    30  
    31  	"go.uber.org/zap"
    32  )
    33  
    34  var (
    35  	optSrcPathPrefix  = flag.String("src-path-prefix", "/var/lib/m3db", "Source Path prefix")
    36  	optSrcNamespace   = flag.String("src-namespace", "metrics", "Source Namespace")
    37  	optSrcShard       = flag.Uint("src-shard", 0, "Source Shard ID")
    38  	optSrcBlockstart  = flag.Int64("src-block-start", 0, "Source Block Start Time [in nsec]")
    39  	optDestPathPrefix = flag.String("dest-path-prefix", "/tmp/m3db-copy", "Destination Path prefix")
    40  	optDestNamespace  = flag.String("dest-namespace", "metrics", "Destination Namespace")
    41  	optDestShard      = flag.Uint("dest-shard", 0, "Destination Shard ID")
    42  	optDestBlockstart = flag.Int64("dest-block-start", 0, "Destination Block Start Time [in nsec]")
    43  	optDestBlockSize  = flag.Duration("dest-block-size", 0, "Destination Block Size")
    44  )
    45  
    46  func main() {
    47  	flag.Parse()
    48  	if *optSrcPathPrefix == "" ||
    49  		*optDestPathPrefix == "" ||
    50  		*optSrcNamespace == "" ||
    51  		*optDestNamespace == "" ||
    52  		*optSrcBlockstart <= 0 ||
    53  		*optDestBlockstart <= 0 {
    54  		flag.Usage()
    55  		os.Exit(1)
    56  	}
    57  
    58  	rawLogger, err := zap.NewDevelopment()
    59  	if err != nil {
    60  		log.Fatalf("unable to create logger: %+v", err)
    61  	}
    62  	logger := rawLogger.Sugar()
    63  
    64  	src := clone.FileSetID{
    65  		PathPrefix: *optSrcPathPrefix,
    66  		Namespace:  *optSrcNamespace,
    67  		Shard:      uint32(*optSrcShard),
    68  		Blockstart: xtime.UnixNano(*optSrcBlockstart),
    69  	}
    70  	dest := clone.FileSetID{
    71  		PathPrefix: *optDestPathPrefix,
    72  		Namespace:  *optDestNamespace,
    73  		Shard:      uint32(*optDestShard),
    74  		Blockstart: xtime.UnixNano(*optDestBlockstart),
    75  	}
    76  
    77  	logger.Infof("source: %+v", src)
    78  	logger.Infof("destination: %+v", dest)
    79  
    80  	opts := clone.NewOptions()
    81  	cloner := clone.New(opts)
    82  	if err := cloner.Clone(src, dest, *optDestBlockSize); err != nil {
    83  		logger.Fatalf("unable to clone: %v", err)
    84  	}
    85  
    86  	logger.Infof("successfully cloned data")
    87  }