package service import ( "bytes" "errors" "net/url" "os/exec" "strings" ) var rsyncOpts = []string{ "--delete-excluded", "--hard-links", "--links", "--perms", "--recursive", "--safe-links", "--sparse", "--times", } func Rsync(dst *url.URL, src *url.URL) error { src2 := *src if !strings.HasSuffix(src2.Path, "/.") { src2.Path = src2.Path + "/." } var stderr bytes.Buffer args := append(rsyncOpts, src2.String(), dst.String()) cmd := exec.Command("rsync", args...) cmd.Stderr = &stderr err := cmd.Run() if err != nil { return errors.New(stderr.String()) } return nil }