// Run builds the command name and executes it, saving the output to the log // file requested in the configuration or a default one if none is specified. // Temporary files with exclusion and inclusion paths are generated, if needed, // and removed at the end of execution. If dryRun is set, just output the // command to be executed and the contents of the exclusion and inclusion lists // to stderr. func (r *RsyncTransport) Run() error { // Create exclude/include lists, if needed err := r.createExcludeFile(r.config.Exclude) if err != nil { return err } defer os.Remove(r.excludeFile) err = r.createIncludeFile(r.config.Include) if err != nil { return err } defer os.Remove(r.includeFile) // Build the full rsync command line cmd := []string{rsyncCmd, "-av", "--delete", "--numeric-ids"} if r.excludeFile != "" { cmd = append(cmd, fmt.Sprintf("--exclude-from=%s", r.excludeFile)) cmd = append(cmd, "--delete-excluded") } if r.includeFile != "" { cmd = append(cmd, fmt.Sprintf("--include-from=%s", r.includeFile)) } if len(r.config.ExtraArgs) != 0 { for _, v := range r.config.ExtraArgs { cmd = append(cmd, v) } } // In rsync, the source needs to ends with a slash or the // source directory will be created inside the destination. // The exception are the cases where the source already ends // in a slash (ex: /) src := r.buildSource() if !strings.HasSuffix(src, "/") { src = src + "/" } cmd = append(cmd, src) cmd = append(cmd, r.buildDest()) r.log.Verbosef(1, "Command: %s\n", strings.Join(cmd, " ")) // Execute the command if !r.dryRun { return execute.RunCommand("RSYNC", cmd, r.log, r.execute, nil, nil) } return nil }
// Run forms the command name and executes it, saving the output to the log // file requested in the configuration or a default one if none is specified. // Temporary files with exclusion and inclusion paths are generated, if needed, // and removed at the end of execution. If dryRun is set, just output the // command to be executed and the contents of the exclusion and inclusion lists // to stderr. func (r *RcloneTransport) Run() error { // Create exclude/include lists, if needed err := r.createExcludeFile(r.config.Exclude) if err != nil { return err } defer os.Remove(r.excludeFile) err = r.createIncludeFile(r.config.Include) if err != nil { return err } defer os.Remove(r.includeFile) // Build the full rclone command line cmd := []string{rcloneCmd, "sync", "-v"} if r.excludeFile != "" { cmd = append(cmd, fmt.Sprintf("--exclude-from=%s", r.excludeFile)) } if r.includeFile != "" { cmd = append(cmd, fmt.Sprintf("--include-from=%s", r.includeFile)) } if len(r.config.ExtraArgs) != 0 { for _, v := range r.config.ExtraArgs { cmd = append(cmd, v) } } cmd = append(cmd, r.buildSource()) cmd = append(cmd, r.buildDest()) r.log.Verbosef(1, "Command: %s\n", strings.Join(cmd, " ")) // Execute the command if !r.dryRun { return execute.RunCommand("RCLONE", cmd, r.log, r.execute, nil, nil) } return nil }
// Run forms the command name and executes it, saving the output to the log // file requested in the configuration or a default one if none is specified. // Temporary files with exclusion and inclusion paths are generated, if needed, // and removed at the end of execution. If dryRun is set, just output the // command to be executed and the contents of the exclusion and inclusion lists // to stderr. func (r *RdiffBackupTransport) Run() error { // Create exclude/include lists, if needed err := r.createExcludeFile(r.config.Exclude) if err != nil { return err } defer os.Remove(r.excludeFile) err = r.createIncludeFile(r.config.Include) if err != nil { return err } defer os.Remove(r.includeFile) // Build the full rclone command line cmd := []string{ rdiffBackupCmd, "--verbosity=5", "--terminal-verbosity=5", "--preserve-numerical-ids", "--exclude-sockets", "--force"} if r.excludeFile != "" { cmd = append(cmd, fmt.Sprintf("--exclude-globbing-filelist=%s", r.excludeFile)) } if r.includeFile != "" { cmd = append(cmd, fmt.Sprintf("--include-globbing-filelist=%s", r.includeFile)) } if len(r.config.ExtraArgs) != 0 { for _, v := range r.config.ExtraArgs { cmd = append(cmd, v) } } // rdiff-backup uses double colons as host/destination separators. src := r.config.SourceDir if r.config.SourceHost != "" { src = r.config.SourceHost + "::" + src } dst := r.config.DestDir if r.config.DestHost != "" { dst = r.config.DestHost + "::" + dst } cmd = append(cmd, src) cmd = append(cmd, dst) // Execute the command spam := []string{ "POSIX ACLs not supported", "Unable to import win32security module", "not supported by filesystem at", "escape_dos_devices not required by filesystem at", "Reading globbing filelist", "Updated mirror temp file.* does not match source", "/.gvfs"} r.log.Verbosef(1, "Command: %s\n", strings.Join(cmd, " ")) if !r.dryRun { // Run err = execute.RunCommand("RDIFF-BACKUP", cmd, r.log, r.execute, spam, spam) if err != nil { return err } } // Remove older files, if requested. if r.config.RdiffBackupMaxAge != 0 { cmd := []string{ rdiffBackupCmd, fmt.Sprintf("--remove-older-than=%dD", r.config.RdiffBackupMaxAge), "--force", dst} r.log.Verbosef(1, "Command: %s\n", strings.Join(cmd, " ")) if !r.dryRun { return execute.RunCommand("RDIFF-BACKUP", cmd, r.log, r.execute, spam, spam) } } return nil }