Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/sync: support existing and ignore-existing flag #3566

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ Supported storage systems: https://juicefs.com/docs/community/how_to_setup_objec
Name: "include",
Usage: "don't exclude Key matching PATTERN, need to be used with \"--exclude\" option",
},
&cli.BoolFlag{
Name: "existing",
Aliases: []string{"ignore-non-existing"},
Usage: "skip creating new files on destination",
},
&cli.BoolFlag{
Name: "ignore-existing",
Usage: "skip updating files that already exist on destination",
},
&cli.BoolFlag{
Name: "links",
Aliases: []string{"l"},
Expand Down
100 changes: 52 additions & 48 deletions pkg/sync/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,33 @@ import (
)

type Config struct {
StorageClass string
Start string
End string
Threads int
HTTPPort int
Update bool
ForceUpdate bool
Perms bool
Dry bool
DeleteSrc bool
DeleteDst bool
Dirs bool
Exclude []string
Include []string
Links bool
Limit int64
Manager string
Workers []string
BWLimit int
NoHTTPS bool
Verbose bool
Quiet bool
CheckAll bool
CheckNew bool
Env map[string]string
StorageClass string
Start string
End string
Threads int
HTTPPort int
Update bool
ForceUpdate bool
Perms bool
Dry bool
DeleteSrc bool
DeleteDst bool
Dirs bool
Exclude []string
Include []string
Existing bool
IgnoreExisting bool
Links bool
Limit int64
Manager string
Workers []string
BWLimit int
NoHTTPS bool
Verbose bool
Quiet bool
CheckAll bool
CheckNew bool
Env map[string]string
}

func envList() []string {
Expand Down Expand Up @@ -122,29 +124,31 @@ func NewConfigFromCli(c *cli.Context) *Config {
}

cfg := &Config{
Start: c.String("start"),
End: c.String("end"),
Threads: c.Int("threads"),
Update: c.Bool("update"),
ForceUpdate: c.Bool("force-update"),
Perms: c.Bool("perms"),
Dirs: c.Bool("dirs"),
Dry: c.Bool("dry"),
DeleteSrc: c.Bool("delete-src"),
DeleteDst: c.Bool("delete-dst"),
Exclude: c.StringSlice("exclude"),
Include: c.StringSlice("include"),
Links: c.Bool("links"),
Limit: c.Int64("limit"),
Workers: c.StringSlice("worker"),
Manager: c.String("manager"),
BWLimit: c.Int("bwlimit"),
NoHTTPS: c.Bool("no-https"),
Verbose: c.Bool("verbose"),
Quiet: c.Bool("quiet"),
CheckAll: c.Bool("check-all"),
CheckNew: c.Bool("check-new"),
Env: make(map[string]string),
Start: c.String("start"),
End: c.String("end"),
Threads: c.Int("threads"),
Update: c.Bool("update"),
ForceUpdate: c.Bool("force-update"),
Perms: c.Bool("perms"),
Dirs: c.Bool("dirs"),
Dry: c.Bool("dry"),
DeleteSrc: c.Bool("delete-src"),
DeleteDst: c.Bool("delete-dst"),
Exclude: c.StringSlice("exclude"),
Include: c.StringSlice("include"),
Existing: c.Bool("existing"),
IgnoreExisting: c.Bool("ignore-existing"),
Links: c.Bool("links"),
Limit: c.Int64("limit"),
Workers: c.StringSlice("worker"),
Manager: c.String("manager"),
BWLimit: c.Int("bwlimit"),
NoHTTPS: c.Bool("no-https"),
Verbose: c.Bool("verbose"),
Quiet: c.Bool("quiet"),
CheckAll: c.Bool("check-all"),
CheckNew: c.Bool("check-new"),
Env: make(map[string]string),
}
if cfg.Threads <= 0 {
logger.Warnf("threads should be larger than 0, reset it to 1")
Expand Down
10 changes: 10 additions & 0 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,18 @@ func produce(tasks chan<- object.Object, src, dst object.ObjectStorage, srckeys,

// FIXME: there is a race when source is modified during coping
if dstobj == nil || obj.Key() < dstobj.Key() {
if config.Existing {
skipped.Increment()
handled.Increment()
continue
}
tasks <- obj
} else { // obj.key == dstobj.key
if config.IgnoreExisting {
skipped.Increment()
handled.Increment()
continue
}
if config.ForceUpdate ||
(config.Update && obj.Mtime().Unix() > dstobj.Mtime().Unix()) ||
(!config.Update && obj.Size() != dstobj.Size()) {
Expand Down