This repository was archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathrsync.go
More file actions
67 lines (58 loc) · 1.39 KB
/
rsync.go
File metadata and controls
67 lines (58 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
var lastSyncError = ""
func Sync(via string, c SSHCredentials, src, dst string, verbose bool) {
args := []string{
// "--verbose",
// "--stats",
"--perms",
"--recursive",
"--links",
"--times",
"--inplace",
"--itemize-changes",
"--delete",
"--force",
"--executability",
"--compress",
}
ripath := getRsyncIgnorePath()
if ripath != "" {
args = append(args, `--exclude-from='`+ripath+`'`)
}
if strings.HasPrefix(via, "rsync://") {
args = append(args, filepath.Join(src)+"/.")
args = append(args, via)
} else {
args = append(args, fmt.Sprintf(`-e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -i "%s" -p %v'`, c.SSHKeyPath, c.SSHGuestPort))
args = append(args, "--rsync-path='sudo rsync'")
args = append(args, src, fmt.Sprintf("%s@%s:%s", c.SSHUser, c.IPAddress, dst))
}
cmd := Exec("rsync", args...)
if verbose {
fmt.Printf("rsync %v\n", strings.Join(args, " "))
cmd.Stdout = os.Stdout
}
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
// don't show duplicate errors
if lastSyncError != err.Error() {
fmt.Printf("error: %v\n", err)
}
lastSyncError = err.Error()
}
}
func getRsyncIgnorePath() string {
if _, err := os.Stat(".rsyncignore"); err == nil {
abs, err := filepath.Abs(".rsyncignore")
if err == nil {
return abs
}
}
return ""
}