@@ -4,16 +4,36 @@ import (
44 "fmt"
55 "github.com/RSE-Cambridge/data-acc/internal/pkg/registry"
66 "log"
7+ "path"
8+ "strings"
79)
810
911func processDataCopy (volume registry.Volume , request registry.DataCopyRequest ) error {
1012 cmd , err := generateDataCopyCmd (volume , request )
1113 if err != nil {
1214 return err
1315 }
16+ if cmd == "" {
17+ log .Println ("No files to copy for:" , volume .Name )
18+ return nil
19+ }
20+
21+ log .Printf ("Doing copy: %s" , cmd )
1422
15- log .Printf ("FAKE copy: %s" , cmd )
16- return nil
23+ // Make sure global dir is setup correctly
24+ // TODO: share code with mount better
25+ // TODO: Probably should all get setup in fs-ansible really!!
26+ mountDir := fmt .Sprintf ("/mnt/lustre/%s" , volume .UUID )
27+ sharedDir := path .Join (mountDir , "/global" )
28+ if err := mkdir ("localhost" , sharedDir ); err != nil {
29+ return err
30+ }
31+ if err := fixUpOwnership ("localhost" , volume .Owner , volume .Group , sharedDir ); err != nil {
32+ return err
33+ }
34+
35+ // Do the copy
36+ return runner .Execute ("localhost" , cmd )
1737}
1838
1939func generateDataCopyCmd (volume registry.Volume , request registry.DataCopyRequest ) (string , error ) {
@@ -22,24 +42,31 @@ func generateDataCopyCmd(volume registry.Volume, request registry.DataCopyReques
2242 return "" , err
2343 }
2444
25- cmd := fmt .Sprintf ("sudo su `getent passwd %d | cut -d: -f1` %s" , volume .Owner , rsync )
45+ cmd := fmt .Sprintf ("sudo -g '#%d' -u '#%d' %s" , volume .Group , volume .Owner , rsync )
46+ dacHostBufferPath := fmt .Sprintf ("/mnt/lustre/%s/global" , volume .UUID )
47+ cmd = fmt .Sprintf ("bash -c \" export DW_JOB_STRIPED='%s' && %s\" " , dacHostBufferPath , cmd )
2648 return cmd , nil
2749}
2850
2951func generateRsyncCmd (volume registry.Volume , request registry.DataCopyRequest ) (string , error ) {
3052 if request .Source == "" && request .Destination == "" {
31- log .Println ("No files to copy for:" , volume .Name )
3253 return "" , nil
3354 }
3455
3556 var flags string
3657 if request .SourceType == registry .Directory {
37- flags = "-r "
58+ flags = "-r -ospgu --stats "
3859 } else if request .SourceType == registry .File {
39- flags = ""
60+ flags = "-ospgu --stats "
4061 } else {
4162 return "" , fmt .Errorf ("unsupported source type %s for volume: %s" , request .SourceType , volume .Name )
4263 }
4364
44- return fmt .Sprintf ("rsync %s%s %s" , flags , request .Source , request .Destination ), nil
65+ return fmt .Sprintf ("rsync %s %s %s" , flags ,
66+ escapePath (request .Source ),
67+ escapePath (request .Destination )), nil
68+ }
69+
70+ func escapePath (path string ) string {
71+ return strings .Replace (path , "$DW_JOB_STRIPED" , "\\ $DW_JOB_STRIPED" , 1 )
4572}
0 commit comments