-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
67 lines (54 loc) · 1.28 KB
/
main.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
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
// Send @RSYNCD x.x\n
// Send modname\n
// Send arugment with mod list\0 filter list write(0) \n
// handshake
// batch seed
// Recv file list
//
package main
import (
"flag"
"fmt"
"github.com/spf13/viper"
"log"
"rsync-os/rsync"
"rsync-os/storage"
"time"
)
func ClientS3(src string, dest string) {
addr, module, path, err := rsync.SplitURI(src)
if err != nil {
log.Println("Invaild URI")
return
}
log.Println(module, path)
ppath := rsync.TrimPrepath(path)
if viper.GetStringMapString(dest) == nil {
log.Println("Lack of ", dest)
return
}
// Config
dbconf := viper.GetStringMapString(dest + ".boltdb")
minioConf := viper.GetStringMapString(dest)
stor, _ := storage.NewMinio(module, ppath, dbconf["path"], minioConf["endpoint"], minioConf["keyaccess"], minioConf["keysecret"], false)
defer stor.Close()
client, err := rsync.SocketClient(stor, addr, module, ppath, nil)
if err != nil {
panic("rsync client fails to initialize")
}
if err := client.Sync(); err != nil {
panic(err)
}
}
func main() {
loadConfigIfExists()
flag.Parse()
args := flag.Args()
if len(args) < 2 {
fmt.Println("Usage: rsync-os [OPTION]... rsync://[USER@]HOST[:PORT]/SRC")
return
}
startTime := time.Now()
ClientS3(args[0], args[1])
log.Println("Duration:", time.Since(startTime))
}