github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/cmd/sync/sync.go (about) 1 package sync 2 3 import ( 4 "context" 5 6 "github.com/ncw/rclone/cmd" 7 "github.com/ncw/rclone/fs/operations" 8 "github.com/ncw/rclone/fs/sync" 9 "github.com/spf13/cobra" 10 ) 11 12 var ( 13 createEmptySrcDirs = false 14 ) 15 16 func init() { 17 cmd.Root.AddCommand(commandDefintion) 18 commandDefintion.Flags().BoolVarP(&createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after sync") 19 } 20 21 var commandDefintion = &cobra.Command{ 22 Use: "sync source:path dest:path", 23 Short: `Make source and dest identical, modifying destination only.`, 24 Long: ` 25 Sync the source to the destination, changing the destination 26 only. Doesn't transfer unchanged files, testing by size and 27 modification time or MD5SUM. Destination is updated to match 28 source, including deleting files if necessary. 29 30 **Important**: Since this can cause data loss, test first with the 31 ` + "`" + `--dry-run` + "`" + ` flag to see exactly what would be copied and deleted. 32 33 Note that files in the destination won't be deleted if there were any 34 errors at any point. 35 36 It is always the contents of the directory that is synced, not the 37 directory so when source:path is a directory, it's the contents of 38 source:path that are copied, not the directory name and contents. See 39 extended explanation in the ` + "`" + `copy` + "`" + ` command above if unsure. 40 41 If dest:path doesn't exist, it is created and the source:path contents 42 go there. 43 44 **Note**: Use the ` + "`-P`" + `/` + "`--progress`" + ` flag to view real-time transfer statistics 45 `, 46 Run: func(command *cobra.Command, args []string) { 47 cmd.CheckArgs(2, 2, command, args) 48 fsrc, srcFileName, fdst := cmd.NewFsSrcFileDst(args) 49 cmd.Run(true, true, command, func() error { 50 if srcFileName == "" { 51 return sync.Sync(context.Background(), fdst, fsrc, createEmptySrcDirs) 52 } 53 return operations.CopyFile(context.Background(), fdst, fsrc, srcFileName, srcFileName) 54 }) 55 }, 56 }