-
Notifications
You must be signed in to change notification settings - Fork 20
/
rsync.go
35 lines (31 loc) · 975 Bytes
/
rsync.go
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
package sync
import (
"fmt"
"os/exec"
"strings"
"time"
log "github.com/sirupsen/logrus"
)
// StartRsync path to target rsync server on given interval
func StartRsync(done <-chan struct{}, host string, port int, syncs []Sync, interval time.Duration) {
go func() {
for {
select {
case <-time.After(interval):
for _, sync := range syncs {
err := executeRsync(sync.Source, fmt.Sprintf("rsync://%s:%d/%s/", host, port, strings.Replace(sync.Destination, "/", "_", -1)))
if err != nil {
log.Errorf("Error while running rsync: %s", err)
}
}
case <-done:
return
}
}
}()
}
func executeRsync(sourceDir, destination string) error {
cmd := exec.Command("/usr/bin/rsync", "--recursive", "--times", "--links", "--devices", "--specials", "--compress", sourceDir, destination)
// TODO: How to display sync completed /failed? Cannot print terminal because messing out terminal attachment. Desktop notification?
return cmd.Run()
}