MCPcopy
hub / github.com/kopia/kopia / setup

Method setup

cli/command_repository_sync.go:41–81  ·  view source on GitHub ↗
(svc advancedAppServices, parent commandParent)

Source from the content-addressed store, hash-verified

39}
40
41func (c *commandRepositorySyncTo) setup(svc advancedAppServices, parent commandParent) {
42 cmd := parent.Command("sync-to", "Synchronizes the contents of this repository to another location")
43 cmd.Flag("update", "Whether to update blobs present in destination and source if the source is newer.").Default("true").BoolVar(&c.repositorySyncUpdate)
44 cmd.Flag("delete", "Whether to delete blobs present in destination but not source.").BoolVar(&c.repositorySyncDelete)
45 cmd.Flag("dry-run", "Do not perform copying.").Short('n').BoolVar(&c.repositorySyncDryRun)
46 cmd.Flag("parallel", "Copy parallelism.").Default("1").IntVar(&c.repositorySyncParallelism)
47 cmd.Flag("must-exist", "Fail if destination does not have repository format blob.").BoolVar(&c.repositorySyncDestinationMustExist)
48 cmd.Flag("times", "Synchronize blob times if supported.").BoolVar(&c.repositorySyncTimes)
49
50 c.out.setup(svc)
51 c.progress = svc.getProgress()
52
53 for _, prov := range svc.storageProviders() {
54 // Set up 'sync-to' subcommand
55 f := prov.NewFlags()
56 cc := cmd.Command(prov.Name, "Synchronize repository data to another repository in "+prov.Description)
57 f.Setup(svc, cc)
58 cc.Action(func(kpc *kingpin.ParseContext) error {
59 return svc.runAppWithContext(kpc.SelectedCommand, func(ctx context.Context) error {
60 st, err := f.Connect(ctx, false, 0)
61 if err != nil {
62 return errors.Wrap(err, "can't connect to storage")
63 }
64
65 rep, err := svc.openRepository(ctx, true)
66 if err != nil {
67 return errors.Wrap(err, "open repository")
68 }
69
70 defer rep.Close(ctx) //nolint:errcheck
71
72 dr, ok := rep.(repo.DirectRepository)
73 if !ok {
74 return errors.New("sync only supports directly-connected repositories")
75 }
76
77 return c.runSyncWithStorage(ctx, dr.BlobReader(), st)
78 })
79 })
80 }
81}
82
83const syncProgressInterval = 300 * time.Millisecond
84

Callers

nothing calls this directly

Calls 10

runSyncWithStorageMethod · 0.95
CommandMethod · 0.80
getProgressMethod · 0.65
storageProvidersMethod · 0.65
SetupMethod · 0.65
runAppWithContextMethod · 0.65
ConnectMethod · 0.65
openRepositoryMethod · 0.65
CloseMethod · 0.65
BlobReaderMethod · 0.65

Tested by

no test coverage detected