@@ -22,11 +22,14 @@ import (
22
22
"os"
23
23
"os/exec"
24
24
"strings"
25
+
26
+ "dcrcli/dcrlogger"
25
27
)
26
28
27
29
type RemoteCred struct {
28
30
Username string
29
31
Available bool
32
+ Dcrlog * dcrlogger.DCRLogger
30
33
}
31
34
32
35
func (rc * RemoteCred ) Get () error {
@@ -38,12 +41,17 @@ func (rc *RemoteCred) Get() error {
38
41
if err != nil {
39
42
return err
40
43
}
44
+
41
45
rc .Username = strings .TrimSuffix (username , "\n " )
46
+ rc .Dcrlog .Debug (fmt .Sprintf ("passwordless ssh username %s:" , rc .Username ))
47
+
42
48
if rc .Username == "" {
43
49
println ("WARNING: PasswordLess SSH Username is empty assuming all nodes local" )
44
50
rc .Available = false
51
+ rc .Dcrlog .Debug ("passwordless ssh username left blank assuming all nodes local" )
45
52
} else {
46
53
rc .Available = true
54
+ rc .Dcrlog .Debug ("passwordless ssh username provided" )
47
55
}
48
56
49
57
return nil
@@ -61,63 +69,64 @@ type DestDir struct {
61
69
Path []byte
62
70
}
63
71
64
- // Copy job
65
- // state:
66
- // N - not started
67
- // P - Progressing
68
- // A - Aborted
69
- // C - Completed successfully
70
- type FSCopyJob struct {
71
- Src SourceDir
72
- Dst DestDir
73
- State string
74
- Output * bytes.Buffer
75
- }
76
-
77
72
// example rsync -a --include='mongod.log*' --exclude='*' --include='*/' ubuntu@ip-10-0-0-246:/home/ubuntu/testcluster/dbp/ .
78
73
type FSCopyJobWithPattern struct {
79
74
CopyJobDetails * FSCopyJob
80
75
CurrentFileName string
76
+ Dcrlog * dcrlogger.DCRLogger
81
77
}
82
78
83
- func (fcj * FSCopyJobWithPattern ) StartCopyWithPattern () error {
84
- if fcj .CopyJobDetails .Src .IsLocal {
85
- return fcj .StartCopyLocalWithPattern ()
79
+ func (fcjwp * FSCopyJobWithPattern ) StartCopyWithPattern () error {
80
+ if fcjwp .CopyJobDetails .Src .IsLocal {
81
+ return fcjwp .StartCopyLocalWithPattern ()
86
82
}
87
- return fcj .StartCopyRemoteWithPattern ()
83
+ return fcjwp .StartCopyRemoteWithPattern ()
88
84
}
89
85
90
- func (fcj * FSCopyJobWithPattern ) StartCopyLocalWithPattern () error {
86
+ func (fcjwp * FSCopyJobWithPattern ) StartCopyLocalWithPattern () error {
91
87
return nil
92
88
}
93
89
94
- func (fcj * FSCopyJobWithPattern ) StartCopyRemoteWithPattern () error {
90
+ func (fcjwp * FSCopyJobWithPattern ) StartCopyRemoteWithPattern () error {
95
91
var cmd * exec.Cmd
96
92
97
- filepattern := `'` + fcj .CurrentFileName + `*` + `'`
93
+ filepattern := `'` + fcjwp .CurrentFileName + `*` + `'`
98
94
excludepattern := `'` + `*` + `'`
99
95
100
96
// we invoke bash shell because the wildcards are interpretted by bash shell not the rsync program
97
+ fcjwp .Dcrlog .Debug (
98
+ fmt .Sprintf (
99
+ "preparing command rsync -az --include=%s --exclude=%s --info=progress2 %s@%s:%s/ %s" ,
100
+ filepattern ,
101
+ excludepattern ,
102
+ fcjwp .CopyJobDetails .Src .Username ,
103
+ fcjwp .CopyJobDetails .Src .Hostname ,
104
+ fcjwp .CopyJobDetails .Src .Path ,
105
+ fcjwp .CopyJobDetails .Dst .Path ,
106
+ ),
107
+ )
108
+
101
109
cmd = exec .Command (
102
110
"bash" ,
103
111
"-c" ,
104
112
fmt .Sprintf (
105
113
"rsync -az --include=%s --exclude=%s --info=progress2 %s@%s:%s/ %s" ,
106
114
filepattern ,
107
115
excludepattern ,
108
- fcj .CopyJobDetails .Src .Username ,
109
- fcj .CopyJobDetails .Src .Hostname ,
110
- fcj .CopyJobDetails .Src .Path ,
111
- fcj .CopyJobDetails .Dst .Path ,
116
+ fcjwp .CopyJobDetails .Src .Username ,
117
+ fcjwp .CopyJobDetails .Src .Hostname ,
118
+ fcjwp .CopyJobDetails .Src .Path ,
119
+ fcjwp .CopyJobDetails .Dst .Path ,
112
120
))
113
121
114
- cmd .Stdout = fcj .CopyJobDetails .Output
122
+ cmd .Stdout = fcjwp .CopyJobDetails .Output
115
123
116
124
stderr , err := cmd .StderrPipe ()
117
125
if err != nil {
118
126
return err
119
127
}
120
128
129
+ fcjwp .Dcrlog .Debug ("rsync command start" )
121
130
err = cmd .Start ()
122
131
if err != nil {
123
132
return err
@@ -126,21 +135,47 @@ func (fcj *FSCopyJobWithPattern) StartCopyRemoteWithPattern() error {
126
135
_ , err = io .ReadAll (stderr )
127
136
if err != nil {
128
137
_ = cmd .Process .Kill ()
138
+ fcjwp .Dcrlog .Debug (
139
+ fmt .Sprintf ("StartCopyRemoteWithPattern: Error reading from stderr pipe %w" , err ),
140
+ )
129
141
return fmt .Errorf ("StartCopyRemoteWithPattern: Error reading from stderr pipe %w" , err )
130
142
}
131
143
132
144
err = cmd .Wait ()
133
145
if err != nil {
146
+ fcjwp .Dcrlog .Debug (
147
+ fmt .Sprintf ("StartCopyRemoteWithPattern: error doing remote copy job wait %w" , err ),
148
+ )
134
149
return fmt .Errorf ("StartCopyRemoteWithPattern: error doing remote copy job wait %w" , err )
135
150
}
136
151
return nil
137
152
}
138
153
154
+ // Copy job
155
+ // state:
156
+ // N - not started
157
+ // P - Progressing
158
+ // A - Aborted
159
+ // C - Completed successfully
160
+ type FSCopyJob struct {
161
+ Src SourceDir
162
+ Dst DestDir
163
+ State string
164
+ Output * bytes.Buffer
165
+ Dcrlog * dcrlogger.DCRLogger
166
+ }
167
+
139
168
// currently only run for remote source directories
140
169
func (fcj * FSCopyJob ) StartCopyRemote () error {
141
- var cmd * exec.Cmd
170
+ // var cmd *exec.Cmd
142
171
143
- cmd = exec .Command (
172
+ fcj .Dcrlog .Debug (fmt .Sprintf ("preparing command rsync -az --info=progress2 %s@%s:%s/ %s" ,
173
+ fcj .Src .Username ,
174
+ fcj .Src .Hostname ,
175
+ fcj .Src .Path ,
176
+ fcj .Dst .Path ))
177
+
178
+ cmd := exec .Command (
144
179
"rsync" ,
145
180
"-az" ,
146
181
"--info=progress2" ,
@@ -159,6 +194,7 @@ func (fcj *FSCopyJob) StartCopyRemote() error {
159
194
return err
160
195
}
161
196
197
+ fcj .Dcrlog .Debug ("starting rsync command" )
162
198
err = cmd .Start ()
163
199
if err != nil {
164
200
return err
@@ -167,11 +203,13 @@ func (fcj *FSCopyJob) StartCopyRemote() error {
167
203
_ , err = io .ReadAll (stderr )
168
204
if err != nil {
169
205
_ = cmd .Process .Kill ()
170
- return fmt .Errorf ("Error reading from stderr pipe %w" , err )
206
+ fcj .Dcrlog .Debug (fmt .Sprintf ("error reading from stderr pipe %w" , err ))
207
+ return fmt .Errorf ("error reading from stderr pipe %w" , err )
171
208
}
172
209
173
210
err = cmd .Wait ()
174
211
if err != nil {
212
+ fcj .Dcrlog .Debug (fmt .Sprintf ("error doing remote copy job wait %w" , err ))
175
213
return fmt .Errorf ("error doing remote copy job wait %w" , err )
176
214
}
177
215
0 commit comments