forked from kaiakz/rsync-os
/
main.go
110 lines (87 loc) · 2.26 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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/sirupsen/logrus"
"log"
"path/filepath"
"github.com/Si-Huan/rsync-os/rsync"
"github.com/Si-Huan/rsync-os/storage"
"time"
"github.com/spf13/viper"
)
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, logrus.New())
if err != nil {
panic("rsync client fails to initialize")
}
if err := client.Sync(); err != nil {
panic(err)
}
}
func ClientTb(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")
tbConf := viper.GetStringMapString(dest)
log.Println(module, ppath)
bucket := filepath.Join(tbConf["base"], module)
stor, err := storage.NewTeambition(bucket, ppath, dbconf["path"], tbConf["cookie"])
if err != nil {
panic(err)
}
defer stor.Close()
client, err := rsync.SocketClient(stor, addr, module, ppath, map[string][]string{"--exclude":{"adir/","*.txt"}},logrus.New())
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])
ClientTb(args[0], args[1])
log.Println("Duration:", time.Since(startTime))
}