func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() == 0 { return flag.ErrHelp } name := f.Arg(0) finder, err := cmd.Finder() if err != nil { return err } net, err := finder.Network(ctx, cmd.path) if err != nil { return err } dvs, ok := net.(*object.DistributedVirtualSwitch) if !ok { return fmt.Errorf("%s (%T) is not of type %T", cmd.path, net, dvs) } cmd.DVPortgroupConfigSpec.Name = name task, err := dvs.AddPortgroup(ctx, []types.DVPortgroupConfigSpec{cmd.DVPortgroupConfigSpec}) if err != nil { return err } logger := cmd.ProgressLogger(fmt.Sprintf("adding %s portgroup to dvs %s... ", name, dvs.InventoryPath)) defer logger.Wait() _, err = task.WaitForResult(ctx, logger) return err }
func (cmd *rename) Run(f *flag.FlagSet) error { if f.NArg() != 2 { return flag.ErrHelp } ctx := context.TODO() c, err := cmd.Client() if err != nil { return err } m, err := object.GetCustomFieldsManager(c) if err != nil { return err } key, err := m.FindKey(ctx, f.Arg(0)) if err != nil { return err } name := f.Arg(1) return m.Rename(ctx, key, name) }
func (cmd *change) Run(f *flag.FlagSet) error { if f.NArg() == 0 { return flag.ErrHelp } finder, err := cmd.Finder() if err != nil { return err } cmd.SetAllocation(func(a types.BaseResourceAllocationInfo) { ra := a.GetResourceAllocationInfo() if ra.Shares.Level == "" { ra.Shares = nil } }) for _, arg := range f.Args() { pools, err := finder.ResourcePoolList(context.TODO(), arg) if err != nil { return err } for _, pool := range pools { err := pool.UpdateConfig(context.TODO(), cmd.name, &cmd.ResourceConfigSpec) if err != nil { return err } } } return nil }
func multisnapshotCmd(mysqld *mysqlctl.Mysqld, subFlags *flag.FlagSet, args []string) { concurrency := subFlags.Int("concurrency", 8, "how many compression jobs to run simultaneously") spec := subFlags.String("spec", "-", "shard specification") tablesString := subFlags.String("tables", "", "dump only this comma separated list of tables") skipSlaveRestart := subFlags.Bool("skip-slave-restart", false, "after the snapshot is done, do not restart slave replication") maximumFilesize := subFlags.Uint64("maximum-file-size", 128*1024*1024, "the maximum size for an uncompressed data file") subFlags.Parse(args) if subFlags.NArg() != 2 { relog.Fatal("action multisnapshot requires <db name> <key name>") } shards, err := key.ParseShardingSpec(*spec) if err != nil { relog.Fatal("multisnapshot failed: %v", err) } var tables []string if *tablesString != "" { tables = strings.Split(*tablesString, ",") } filenames, err := mysqld.CreateMultiSnapshot(shards, subFlags.Arg(0), subFlags.Arg(1), tabletAddr, false, *concurrency, tables, *skipSlaveRestart, *maximumFilesize, nil) if err != nil { relog.Fatal("multisnapshot failed: %v", err) } else { relog.Info("manifest locations: %v", filenames) } }
func (cmd *service) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() != 2 { return flag.ErrHelp } service := f.Arg(0) device := f.Arg(1) host, err := cmd.HostSystem() if err != nil { return err } m, err := host.ConfigManager().VirtualNicManager(ctx) if err != nil { return err } var method func(context.Context, string, string) error if cmd.Enable { method = m.SelectVnic } else if cmd.Disable { method = m.DeselectVnic } if method == nil { return flag.ErrHelp } return method(ctx, service, device) }
func commandVtGateSplitQuery(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") splitColumn := subFlags.String("split_column", "", "force the use of this column to split the query") splitCount := subFlags.Int("split_count", 16, "number of splits to generate") keyspace := subFlags.String("keyspace", "", "keyspace to send query to") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateSplitQuery command") } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout, "") if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() r, err := vtgateConn.SplitQuery(ctx, *keyspace, subFlags.Arg(0), *bindVariables, *splitColumn, int64(*splitCount)) if err != nil { return fmt.Errorf("SplitQuery failed: %v", err) } return printJSON(wr.Logger(), r) }
func commandEmergencyReparentShard(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { waitSlaveTimeout := subFlags.Duration("wait_slave_timeout", 30*time.Second, "time to wait for slaves to catch up in reparenting") keyspaceShard := subFlags.String("keyspace_shard", "", "keyspace/shard of the shard that needs to be reparented") newMaster := subFlags.String("new_master", "", "alias of a tablet that should be the new master") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() == 2 { // Legacy syntax: "<keyspace/shard> <tablet alias>". if *newMaster != "" { return fmt.Errorf("cannot use legacy syntax and flag -new_master for action EmergencyReparentShard at the same time") } *keyspaceShard = subFlags.Arg(0) *newMaster = subFlags.Arg(1) } else if subFlags.NArg() != 0 { return fmt.Errorf("action EmergencyReparentShard requires -keyspace_shard=<keyspace/shard> -new_master=<tablet alias>") } keyspace, shard, err := topoproto.ParseKeyspaceShard(*keyspaceShard) if err != nil { return err } tabletAlias, err := topoproto.ParseTabletAlias(*newMaster) if err != nil { return err } return wr.EmergencyReparentShard(ctx, keyspace, shard, tabletAlias, *waitSlaveTimeout) }
func (cmd *add) Run(f *flag.FlagSet) error { var ctx = context.Background() if f.NArg() != 0 { return flag.ErrHelp } finder, err := cmd.Finder() if err != nil { return err } cluster, err := finder.ClusterComputeResource(ctx, cmd.cluster) if err != nil { return nil } err = cmd.Add(ctx, cluster) if err == nil { return nil } // Check if we failed due to SSLVerifyFault and -noverify is set if err := cmd.AcceptThumbprint(err); err != nil { return err } // Accepted unverified thumbprint, try again return cmd.Add(ctx, cluster) }
func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() == 0 { return flag.ErrHelp } finder, err := cmd.Finder() if err != nil { return err } for _, arg := range f.Args() { folders, err := finder.FolderList(ctx, arg) if err != nil { return err } for _, folder := range folders { task, err := folder.Destroy(ctx) if err != nil { return err } err = task.Wait(ctx) if err != nil { return err } } } return nil }
func commandVtGateExecute(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") tabletType := subFlags.String("tablet_type", "master", "tablet type to query") json := subFlags.Bool("json", false, "Output JSON instead of human-readable table") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateExecute command") } t, err := parseTabletType(*tabletType, []topodatapb.TabletType{topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY}) if err != nil { return err } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout) if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() qr, err := vtgateConn.Execute(ctx, subFlags.Arg(0), *bindVariables, t) if err != nil { return fmt.Errorf("Execute failed: %v", err) } if *json { return printJSON(wr.Logger(), qr) } printQueryResult(loggerWriter{wr.Logger()}, qr) return nil }
func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() == 0 { return flag.ErrHelp } client, err := cmd.ClientFlag.Client() if err != nil { return err } finder := find.NewFinder(client, false) for _, path := range f.Args() { dcs, err := finder.DatacenterList(ctx, path) if err != nil { return err } for _, dc := range dcs { task, err := dc.Destroy(ctx) if err != nil { return err } if err := task.Wait(ctx); err != nil { return err } } } return nil }
func (cmd *env) Run(ctx context.Context, f *flag.FlagSet) error { env := envResult(cmd.ClientFlag.Environ(cmd.extra)) if f.NArg() > 1 { return flag.ErrHelp } // Option to just output the value, example use: // password=$(govc env GOVC_PASSWORD) if f.NArg() == 1 { var output []string prefix := fmt.Sprintf("%s=", f.Arg(0)) for _, e := range env { if strings.HasPrefix(e, prefix) { output = append(output, e[len(prefix):]) break } } return cmd.WriteResult(envResult(output)) } return cmd.WriteResult(env) }
func (cmd *upload) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() != 2 { return flag.ErrHelp } m, err := cmd.FileManager() if err != nil { return err } src := f.Arg(0) dst := f.Arg(1) var size int64 var buf *bytes.Buffer if src == "-" { buf = new(bytes.Buffer) size, err = io.Copy(buf, os.Stdin) if err != nil { return err } } else { s, err := os.Stat(src) if err != nil { return err } size = s.Size() } url, err := m.InitiateFileTransferToGuest(ctx, cmd.Auth(), dst, cmd.Attr(), size, cmd.overwrite) if err != nil { return err } u, err := cmd.ParseURL(url) if err != nil { return err } c, err := cmd.Client() if err != nil { return nil } p := soap.DefaultUpload if buf != nil { p.ContentLength = size return c.Client.Upload(buf, u, &p) } if cmd.OutputFlag.TTY { logger := cmd.ProgressLogger("Uploading... ") p.Progress = logger defer logger.Wait() } return c.Client.UploadFile(src, u, nil) }
func (cmd *revert) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() > 1 { return flag.ErrHelp } vm, err := cmd.VirtualMachine() if err != nil { return err } if vm == nil { return flag.ErrHelp } var task *object.Task if f.NArg() == 1 { task, err = vm.RevertToSnapshot(ctx, f.Arg(0), cmd.suppressPowerOn) } else { task, err = vm.RevertToCurrentSnapshot(ctx, cmd.suppressPowerOn) } if err != nil { return err } return task.Wait(ctx) }
func (cmd *insert) Run(ctx context.Context, f *flag.FlagSet) error { vm, err := cmd.VirtualMachine() if err != nil { return err } if vm == nil || f.NArg() != 1 { return flag.ErrHelp } devices, err := vm.Device(ctx) if err != nil { return err } c, err := devices.FindFloppy(cmd.device) if err != nil { return err } img, err := cmd.DatastorePath(f.Arg(0)) if err != nil { return nil } return vm.EditDevice(ctx, devices.InsertImg(c, img)) }
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() != 1 { return flag.ErrHelp } name := f.Arg(0) cmd.configSpec.Name = name folder, err := cmd.FolderOrDefault("network") if err != nil { return err } task, err := folder.CreateDVS(ctx, cmd.DVSCreateSpec) if err != nil { return err } logger := cmd.ProgressLogger(fmt.Sprintf("adding %s to folder %s... ", name, folder.InventoryPath)) defer logger.Wait() _, err = task.WaitForResult(ctx, logger) return err }
func commandVtGateExecuteShards(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") tabletType := subFlags.String("tablet_type", "master", "tablet type to query") keyspace := subFlags.String("keyspace", "", "keyspace to send query to") shardsStr := subFlags.String("shards", "", "comma-separated list of shards to send query to") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateExecuteShards command") } t, err := parseTabletType(*tabletType, []pb.TabletType{pb.TabletType_MASTER, pb.TabletType_REPLICA, pb.TabletType_RDONLY}) if err != nil { return err } var shards []string if *shardsStr != "" { shards = strings.Split(*shardsStr, ",") } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout) if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() qr, err := vtgateConn.ExecuteShards(ctx, subFlags.Arg(0), *keyspace, shards, *bindVariables, t) if err != nil { return fmt.Errorf("Execute failed: %v", err) } return printJSON(wr, qr) }
func (cmd *add) Run(f *flag.FlagSet) error { if f.NArg() != 1 { return flag.ErrHelp } ctx := context.TODO() c, err := cmd.Client() if err != nil { return err } m, err := object.GetCustomFieldsManager(c) if err != nil { return err } name := f.Arg(0) def, err := m.Add(ctx, name, "", nil, nil) if err != nil { return err } fmt.Printf("%d\n", def.Key) return nil }
func commandVtTabletRollback(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vttablet client") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 2 { return fmt.Errorf("the <tablet_alias> and <transaction_id> arguments are required for the VtTabletRollback command") } transactionID, err := strconv.ParseInt(subFlags.Arg(1), 10, 64) if err != nil { return err } tabletAlias, err := topoproto.ParseTabletAlias(subFlags.Arg(0)) if err != nil { return err } tabletInfo, err := wr.TopoServer().GetTablet(ctx, tabletAlias) if err != nil { return err } conn, err := tabletconn.GetDialer()(tabletInfo.Tablet, *connectTimeout) if err != nil { return fmt.Errorf("cannot connect to tablet %v: %v", tabletAlias, err) } defer conn.Close(ctx) return conn.Rollback(ctx, &querypb.Target{ Keyspace: tabletInfo.Tablet.Keyspace, Shard: tabletInfo.Tablet.Shard, TabletType: tabletInfo.Tablet.Type, }, transactionID) }
func (cmd *mv) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() < 2 { return flag.ErrHelp } finder, err := cmd.Finder() if err != nil { return err } n := f.NArg() - 1 folder, err := finder.Folder(ctx, f.Arg(n)) if err != nil { return err } objs, err := cmd.ManagedObjects(ctx, f.Args()[:n]) if err != nil { return err } task, err := folder.MoveInto(ctx, objs) if err != nil { return err } logger := cmd.ProgressLogger(fmt.Sprintf("moving %d objects to %s... ", len(objs), folder.InventoryPath)) _, err = task.WaitForResult(ctx, logger) logger.Wait() return err }
func commandSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) { online := subFlags.Bool("online", defaultOnline, "do online copy (optional approximate copy, source and destination tablets will not be put out of serving, minimizes downtime during offline copy)") offline := subFlags.Bool("offline", defaultOffline, "do offline copy (exact copy at a specific GTID, required before shard migration, source and destination tablets will be put out of serving during copy)") excludeTables := subFlags.String("exclude_tables", "", "comma separated list of tables to exclude") strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'vtworker SplitClone --strategy=-help k/s' for more info") sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source") writeQueryMaxRows := subFlags.Int("write_query_max_rows", defaultWriteQueryMaxRows, "maximum number of rows per write query") writeQueryMaxSize := subFlags.Int("write_query_max_size", defaultWriteQueryMaxSize, "maximum size (in bytes) per write query") writeQueryMaxRowsDelete := subFlags.Int("write_query_max_rows_delete", defaultWriteQueryMaxRows, "maximum number of rows per DELETE FROM write query") minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible") destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination") minHealthyRdonlyTablets := subFlags.Int("min_healthy_rdonly_tablets", defaultMinHealthyRdonlyTablets, "minimum number of healthy RDONLY tablets in the source and destination shard at start") maxTPS := subFlags.Int64("max_tps", defaultMaxTPS, "if non-zero, limit copy to maximum number of (write) transactions/second on the destination (unlimited by default)") if err := subFlags.Parse(args); err != nil { return nil, err } if subFlags.NArg() != 1 { subFlags.Usage() return nil, fmt.Errorf("command SplitClone requires <keyspace/shard>") } keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0)) if err != nil { return nil, err } var excludeTableArray []string if *excludeTables != "" { excludeTableArray = strings.Split(*excludeTables, ",") } worker, err := NewSplitCloneWorker(wr, wi.cell, keyspace, shard, *online, *offline, excludeTableArray, *strategy, *sourceReaderCount, *writeQueryMaxRows, *writeQueryMaxSize, *writeQueryMaxRowsDelete, uint64(*minTableSizeForSplit), *destinationWriterCount, *minHealthyRdonlyTablets, *maxTPS) if err != nil { return nil, fmt.Errorf("cannot create split clone worker: %v", err) } return worker, nil }
func (cmd *create) Run(f *flag.FlagSet) error { if f.NArg() == 0 { return flag.ErrHelp } finder, err := cmd.Finder() if err != nil { return err } for _, arg := range f.Args() { dir := path.Dir(arg) base := path.Base(arg) parents, err := finder.ResourcePoolList(context.TODO(), dir) if err != nil { if _, ok := err.(*find.NotFoundError); ok { return fmt.Errorf("cannot create resource pool '%s': parent not found", base) } return err } for _, parent := range parents { _, err = parent.Create(context.TODO(), base, cmd.ResourceConfigSpec) if err != nil { return err } } } return nil }
func mainReqs(args []string, flags *flag.FlagSet) { flags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s %s <package-name>\n", os.Args[0], args[0]) flags.PrintDefaults() } file := flags.String("graphfile", "", fmt.Sprintf("Path to PyPI dependency graph file. Defaults to $GOPATH/src/github.com/beyang/cheerio/data/pypi_graph")) flags.Parse(args[1:]) if flags.NArg() < 1 { flags.Usage() os.Exit(1) } pkg := cheerio.NormalizedPkgName(flags.Arg(0)) var pypiG *cheerio.PyPIGraph if *file == "" { pypiG = cheerio.DefaultPyPIGraph } else { var err error pypiG, err = cheerio.NewPyPIGraph(*file) if err != nil { fmt.Printf("Error creating PyPI graph: %s\n", err) os.Exit(1) } } pkgReq := pypiG.Requires(pkg) pkgReqBy := pypiG.RequiredBy(pkg) fmt.Printf("pkg %s uses (%d):\n %s\nand is used by (%d):\n %s\n", pkg, len(pkgReq), strings.Join(pkgReq, " "), len(pkgReqBy), strings.Join(pkgReqBy, " ")) }
func commandVtGateExecute(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") tabletType := subFlags.String("tablet_type", "master", "tablet type to query") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateExecute command") } t, err := parseTabletType(*tabletType, []topo.TabletType{topo.TYPE_MASTER, topo.TYPE_REPLICA, topo.TYPE_RDONLY}) if err != nil { return err } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout) if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() qr, err := vtgateConn.Execute(ctx, subFlags.Arg(0), *bindVariables, t) if err != nil { return fmt.Errorf("Execute failed: %v", err) } wr.Logger().Printf("%v\n", jscfg.ToJSON(qr)) return nil }
func (cmd *insert) Run(f *flag.FlagSet) error { vm, err := cmd.VirtualMachine() if err != nil { return err } if vm == nil || f.NArg() != 1 { return flag.ErrHelp } devices, err := vm.Device(context.TODO()) if err != nil { return err } c, err := devices.FindCdrom(cmd.device) if err != nil { return err } iso, err := cmd.DatastorePath(f.Arg(0)) if err != nil { return nil } return vm.EditDevice(context.TODO(), devices.InsertIso(c, iso)) }
func (cmd *massSnapshotCreate) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() != 1 { return flag.ErrHelp } _, err := cmd.Client() if err != nil { return err } vms, err := cmd.VirtualMachines(f.Args()) if err != nil { if _, ok := err.(*find.NotFoundError); ok { // Continue with empty VM slice } else { return err } } var t *object.Task //refs := make([]types.ManagedObjectReference, 0, len(vms)) for _, vm := range vms { fmt.Printf("Making a snapshot") t, err = vm.CreateSnapshot(ctx, "mysnapshot", "description", cmd.memory, cmd.quiesce) if err != nil { return err } t.Wait(ctx) //refs = append(refs, vm.Reference()) } return nil }
func virtualRouterCreate(client *contrail.Client, flagSet *flag.FlagSet) { if flagSet.NArg() < 1 { flagSet.Usage() os.Exit(2) } if len(virtualRouterCreateOpts.ipAddress) == 0 { fmt.Fprintf(os.Stderr, "The ip-address option must be specified") os.Exit(2) } matched, err := regexp.MatchString(config.IpAddressPattern, virtualRouterCreateOpts.ipAddress) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) } if !matched { fmt.Fprintf(os.Stderr, "Invalid IP address specified: %s\n", virtualRouterCreateOpts.ipAddress) os.Exit(2) } name := flagSet.Args()[0] vrouter := new(types.VirtualRouter) vrouter.SetName(name) vrouter.SetVirtualRouterIpAddress(virtualRouterCreateOpts.ipAddress) client.Create(vrouter) }
func (cmd *partition) Run(f *flag.FlagSet) error { ctx := context.TODO() if f.NArg() != 1 { return fmt.Errorf("specify device path") } path := f.Args()[0] host, err := cmd.HostSystem() if err != nil { return err } ss, err := host.ConfigManager().StorageSystem(ctx) if err != nil { return err } var hss mo.HostStorageSystem err = ss.Properties(ctx, ss.Reference(), nil, &hss) if err != nil { return nil } info, err := ss.RetrieveDiskPartitionInfo(ctx, path) if err != nil { return err } return cmd.WriteResult(partitionInfo(*info)) }
func commandVerticalSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) { tables := subFlags.String("tables", "", "comma separated list of tables to replicate (used for vertical split)") strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'mysqlctl multirestore -strategy=-help' for more info") sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source") destinationPackCount := subFlags.Int("destination_pack_count", defaultDestinationPackCount, "number of packets to pack in one destination insert") minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible") destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination") if err := subFlags.Parse(args); err != nil { return nil, err } if subFlags.NArg() != 1 { subFlags.Usage() return nil, fmt.Errorf("command VerticalSplitClone requires <destination keyspace/shard>") } keyspace, shard, err := topo.ParseKeyspaceShardString(subFlags.Arg(0)) if err != nil { return nil, err } var tableArray []string if *tables != "" { tableArray = strings.Split(*tables, ",") } worker, err := NewVerticalSplitCloneWorker(wr, wi.cell, keyspace, shard, tableArray, *strategy, *sourceReaderCount, *destinationPackCount, uint64(*minTableSizeForSplit), *destinationWriterCount) if err != nil { return nil, fmt.Errorf("cannot create worker: %v", err) } return worker, nil }
func commandRestoreFromBackup(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("The RestoreFromBackup command requires the <tablet alias> argument.") } tabletAlias, err := topoproto.ParseTabletAlias(subFlags.Arg(0)) if err != nil { return err } tabletInfo, err := wr.TopoServer().GetTablet(ctx, tabletAlias) if err != nil { return err } stream, err := wr.TabletManagerClient().RestoreFromBackup(ctx, tabletInfo.Tablet) if err != nil { return err } for { e, err := stream.Recv() switch err { case nil: logutil.LogEvent(wr.Logger(), e) case io.EOF: return nil default: return err } } }