-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patha-put
executable file
·1368 lines (1204 loc) · 46.6 KB
/
a-put
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
if [[ $# -lt 1 ]]
then
echo "Please give the name of a directory or file to be uploaded to allas as an argument of this command."
echo "For more information, give command:"
echo " a-put -h "
echo ""
exit 1
fi
start_time=$(date +%s)
#default user
user="$USER"
#read static variables
inst_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $inst_root/a_env_conf
source $inst_root/allas-lib
#local variables
bucket_name="not_defined"
fixed_bucket=0
fixed_object=0
tmp_file="not_defined"
print_help=0
os_project_name="$OS_PROJECT_NAME"
input_def=""
mode="swift"
silent=0
#tmp_dir="${tmp_root}/a_put_$$_tmp"
user_answer="x"
free_space_check=1
filelist_level=0
cumulative_size=0
override_mode=0
asis_mode=0
compression=0
tar_extra_options=""
encrypt=""
all_keys=""
include_ameta=1
sdx=0
sdc=0
meta_message=""
check_mode=0
max_files=1000000
# read customer defaults
if [[ -e $HOME/.a_tools_conf ]]; then
customized=1
source $HOME/.a_tools_conf
else
customized=0
fi
#Process command line
while [[ $# -ge 1 ]]
do
case "$1" in
'--bucket' | '-b' )
bucket_name="$2"
#Remove the trailing / if it exist
bucket_name=$(remove_slash_from_ends $bucket_name)
fixed_bucket=1
shift
shift
;;
'--project' | '-p' )
os_project_name="$2"
shift
shift
;;
'--object' | '-o' )
tmp_file="$2"
fixed_object=1
slashcheck=$(echo $tmp_file | grep -c "/")
if [[ $slashcheck -gt 0 ]]; then
echo "Slash characters (/) are not allowed when object name is defined with -o option"
echo "If you want to use slash characters to define a pseudo folder path, add that part of"
echo "object name to the bucket definition (-b):"
echo
echo " a-put -b bucket-name/pseudo/folder/path -o rest-of-object-name "
exit 1
fi
shift
shift
;;
'--lumi' | '-L' )
mode="lumi"
shift
;;
'--allas' | '-A' )
mode="lumi"
shift
;;
'--s3cmd' | '--s3' | '-S' )
mode="s3cmd"
shift
;;
'--compress' | '-c')
compression=1
shift
;;
'--nc' | '-n' )
compression=0
free_space_check=0
shift
;;
'-s' | '--silent' )
silent=1
shift
;;
'-h' | '--help' )
print_help=1
shift
;;
'--user' | '-u' )
user="$2"
shift
shift
;;
'--tmpdir' | '-t' )
tmp_root="$2"
shift
shift
;;
'-x')
free_space_check=0
shift
;;
'--skip-filelist')
filelist_level=2
shift
;;
'--override')
override_mode=1
shift
;;
'--input-list')
list_file=$2
if [[ -e $list_file ]];then
input_def=("$(cat $list_file)")
else
echo "Import file list $list_file not found"
exit 1
fi
shift
shift
;;
'--asis' | '-a' )
compression=0
free_space_check=0
asis_mode=1
fnum=0
shift
;;
'-m' | '--message' )
meta_message=$2
shift
shift
;;
'--no-ameta')
include_ameta=0
shift
;;
'--follow-links' )
tar_extra_options="-h"
shift
;;
'-e' | '--encrypt' )
if [[ $2 == "c4gh" || $2 == "crypt4gh" ]];then
if [[ $(which crypt4gh 2> /dev/null | wc -l ) -ne 1 ]];then
echo ""
echo "crypt4gh is not available!"
echo "Please install crypt4gh if you want to use encryption."
exit 1
fi
encrypt="crypt4gh"
fi
if [[ $2 == "gpg" ]];then
if [[ $(which gpg 2> /dev/null | wc -l ) -ne 1 ]];then
echo ""
echo "gpg is not available!"
echo "Please install crypt4gh if you want to use encryption."
exit 1
fi
encrypt="gpg"
fi
if [[ $encrypt == "" ]]; then
echo "$2 is not a valid encryption method"
exit 1
fi
shift
shift
;;
'--pk' | '--public-key' )
# query file
public_key=$(abspath "$2")
if [[ -e $public_key ]];then
echo Public key: "$public_key"
all_keys=$(echo -en "$all_keys\t--recipient_pk\t$public_key\t")
echo $all_keys
else
echo "Public key $public_key not found"
exit 1
fi
shift
shift
;;
'--sdx' )
if [[ $(which crypt4gh 2> /dev/null | wc -l ) -ne 1 ]];then
echo ""
echo "crypt4gh is not available!"
echo "Please install crypt4gh if you want to use encryption."
exit 1
fi
include_ameta=0
encrypt="crypt4gh"
compression=0
sdx=1
fnum=0
shift
;;
'--sdc' )
if [[ $(which sd-lock-util 2> /dev/null | wc -l ) -ne 1 ]];then
echo ""
echo "sd-lock-util is not available!"
echo "Please install sd-lock-util if you want to use SD Connect based encryption."
echo " https://github.com/CSCfi/sd-lock-util/"
exit 1
fi
sdc=1
include_ameta=0
compression=0
fnum=0
shift
;;
*)
if [[ $input_def == "" ]]; then
input_def=("$1")
num_inputs=1
else
input_def=("$input_def $1")
(( num_inputs = num_inputs + 1 ))
fi
shift # No more switches
;;
esac
done
if [[ $print_help -eq 1 ]]; then
cat <<EOF
This tool is used to upload data from the disk environment
of CSC's supercomputers to Allas and Lumi-o storage environments.
a-put can be used in other environments too.
The basic syntax of the command is:
a-put directory_or_file
By default this tool performs following operations:
1. Ensures that you have working connection to the storage
service.
2. In case of directory, the content of the directory is
collected into a single file (using tar command).
3. By default the data is uploaded to Allas using rclone command
and swift protocol. Lumi-o and Allas with S3 protocol is available too.
NOTE! Data was compression with zstdmt command is no longer done by
default before the upload.
The location were data is stored in the storage server (Allas or Lumi-o) can be defined with
options --bucket (-b) and --object (-o).
The default option is that data that locates in:
- scratch in Puhti is uploaded to bucket: project_number-puhti-SCRATCH
- scratch in Mahti is uploaded to bucket: project_number-mahti-SCRATCH
- projappl in Puhti is uploaded to bucket: project_number-puhti-PROJAPPL
- projappl in Mahti is uploaded to bucket: project_number-mahti-PROJAPPL
- LOCAL_SCRATCH in Puhti is uploaded to bucket: project_number-puhti-LOCAL_SCRATCH
- project in Lumi is uploaded to bucket: project_number-lumi-o-project
- flash in Lumi is uploaded to bucket: project_number-lumi-o-flash
In other cases the data uploaded to by default : username-project_number-MISC
For example for user kkaytaj belonging in project_201234, data
locating in home directory will be uploaded to bucket: kkayttaj-201234-MISC.
The compressed dataset will be stored as one object. The object
name depends on the file name and location. The logic used is that
the possible sub-directory path in Mahti or Puhti is included
in the object name.
E.g. a file called test_1.txt in scratch directory of Puhti can be
stored with commands:
cd /scratch/project_201234
a-put test_1.txt
In this case the file is stored to bucket: 201234-puhti-SCRATCH
as object: test_1.txt.zst
If you have another file called test_1.txt that locates in directory
/scratch/project_201234/project2/sample3 you can store it with commands:
cd /scratch/project_201234/project2/sample3
a-put test_1.txt
Or commands
cd /scratch/project_201234
a-put project2/sample3/test_1.txt
In these cases the file is stored to bucket: 201234-puhti-SCRATCH
as object: project2/sample3/test_1.txt.zst
a-put command line options:
-b, --bucket <bucket_name> Define a name of the bucket into
which the data is uploaded.
-p, --project <project_ID> Upload data into buckets of the defined
project instead of the currently
configured project.
-o, --object <object_name> Define a name for the new object to be
created.
-S, --s3cmd Use S3 protocol instead of swift protocol
for upload.
-n, --nc Do not compress the data that will be uploaded.
(This is now the default mode thus this option is
no longer needed).
-c, --compress The data is compressed using zstdmt command before
upload.
-h, --help Print this help.
-t, --tmpdir Define a directory that will be used to store
temporary files of the upload process.
-s, --silent Less output
-u, --user Define username liked to the data to be uploaded
(default: current username)
--skip-filelist Do not collect information about the files that
the object contains to the metadata file.
Using this option speeds up the upload process
significantly if the directory to be uploaded
contains large amount of files. However, a-find
can't be used to locate objects uploaded this way.
--no-ameta Don't create metadata objects ( _ameta ) for the
stored data objects.
-m, --message "your notes" Add a one line text note to the metadata object.
--override Allow overwriting existing objects.
--input-list <list_file> Give a file that lists the files or directories
to be uploaded to Allas. Each item will be stored as one object.
-a, --asis Copy the given file or content of a directory to Allas
without compression and packing so that each file in the
directory will be copied to Allas as an individual object.
The object name contains the relative path of the file to
be copied.
--follow-links When uploading a directory, include linked files as real files
instead of links.
-e, --encrypt <method> Options: gpg and c4gh. Encrypt data with gpg or crypt4gh.
--pk, --public-key Public key used for crypt4gh encryption.
--sdx Upload data to Allas in format format that is compatible with
the old verision of CSC Sensitive data services: The files are encrypted with
crypt4gh using CSC public key after which the files are imported
to Allas.
With --public-key you can do the encryption with both
CSC and your own public key. By default data is stored to bucket with name:
your-project-number_SD-CONNECT.
--sdc Upload data to Allas in format format that is compatible with
the SD Connect and SD Desktop services. Note that to use this feature
you must set up the allas connection with option --sdc that will guide you
to import project specific SD Connect token that this process needs.
-A, --allas Upload data to Allas with swift protocol in stead of currently set storage server.
Normally this (Allas with swift) is the default and this option is not needed,
but if you have set e.g. Lumi-O as the default storage server, this option can be
used to upload data to Allas without changing the default storage server.
--s3cmd Use Allas with S3 protocol.
-L, --lumi Upload data to Lumi-O with S3 protocol in stead of the default storage server.
If Lumi-O is defined to be the default storage server and this option is not needed.
Related commands: a-find, a-get, a-delete, a-info
EOF
exit
fi
add_os_tar_extra_options
# note about customization
if [[ $silent -eq 0 ]]; then
if [[ $customized -eq 1 ]]; then
echo "Customer settings read from $HOME/.a_tools_conf"
fi
fi
##Assign project to be used if not defined
#if [[ $os_project_name == "" ]]
#then
# if [ -e $HOME/.allas_default ]
# then
# source $HOME/.allas_default
# else
# echo "Default project is not defined"
# source $allas_conf_path -user $user
# echo "os_project_name=$OS_PROJECT_NAME" > $HOME/.allas_default
# echo "Default allas project is stored to \$HOME/.allas_default"
# echo ""
# fi
# source $HOME/.allas_default
#fi
# Check for object name - asis conflict
if [[ $asis_mode -eq 1 ]] && [[ $fixed_object -eq 1 ]]; then
echo "In asis-mode (-a, --asis) you can't use -o or --object to define object name"
echo "In asis mode the object name is always based on the original file name"
exit 1
fi
#Check if zstdmt is needed and available
if [[ $compression -eq 1 ]]; then
if [[ $(which zstdmt 2> /dev/null | wc -l ) -ne 1 ]];then
echo "Compression command: zstdmt is not available"
echo "Please install zstdmt or use a-put without compression"
exit 1
fi
fi
#Check if rclone is available
if [[ $(which rclone 2> /dev/null | wc -l ) -ne 1 ]];then
echo ""
echo "rclone is not available!"
echo "Please install rclone."
exit 1
fi
#check SD Connect settings if that is used
if [[ $sdc -eq 1 ]]; then
sdc_check=$(sd-lock-util pubkey | grep -c "BEGIN CRYPT4GH PUBLIC KEY")
if [[ $sdc_check -ne 1 ]]; then
echo "Connection to SD Connect service is not working."
echo "Please open or refresh the connection"
echo "by running command:"
echo ""
echo " source $allas_conf_path --sdc"
exit 1
fi
fi
# s3cmd mode
if [[ $mode == "s3cmd" ]]; then
storage_server="s3allas"
storage_name="Allas"
#rclone_copy_options="--s3-chunk-size 10000"
fi
if [[ $mode == "lumi" ]]; then
storage_server="lumi-o"
storage_name="Lumi-o"
fi
#check free space in tmpdir
if [[ $free_space_check -eq 1 ]]; then
if [[ $local_host == "puhti" || $local_host == "mahti" ]];then
free_space=$(list-dir-quota $tmp_root | tail -1 | tr "/" " " | awk '{ a=$3-$2}{print a}')
else
free_space=$(df $tmp_root | tail -1 | awk '{print $4}')
fi
else
free_space=10000000000
fi
if [[ $silent -eq 0 ]] ; then
echo "Files or directories to be uploaded: $input_def"
fi
#Create file list in case of asis
if [[ $asis_mode -eq 1 ]];then
if [[ $num_inputs -gt 1 ]]; then
echo "In asis and sensitive data mode you can define only one file or directory to be imported."
exit 1
fi
#For field separator changed to allow spaces in file names
#IFS contains the default field separator
SAVEIFS="$IFS"
#input_def=($(echo $input_def))
IFS=$(echo -en "\t\n\b")
#parse the file names from the target directory
input_def=("$(find $input_def -type f)")
#IFS=$SAVEFS
num_to_import=($(echo "$input_def" | wc -l ))
#IFS=$(echo -en " \n\b")
if [[ $num_to_import -lt 1 ]]; then
echo "Input definition: $one_input_def"
echo "don't return any files to input"
exit 1
fi
fi
make_temp_dir
printf "%18s %25s %6s %8s %25s\n" "Date" "Name" "Files" "Size(kB)" "Location in $storage_name" >> ${tmp_dir}/upload.log
for input in $input_def
do
#Check if connection works and update if needed and possible
if [[ $mode == "swift" ]]
then
storage_server="allas"
storage_name="Allas"
if [[ $silent -eq 0 ]] ; then
check_swift_connection
else
check_swift_connection > /dev/null
fi
fi
filelist_level_orig=$filelist_level
if [[ $silent -eq 0 ]] ; then
echo "Processing: $input"
fi
if [[ ! -e $input ]] ; then
echo "File or directory $input does not exist!"
exit 1
fi
#Remove the trailing / if it exist
if [[ $(echo -n "$input" | tail -c 1) == "/" ]]
then
input=${input%/}
fi
#check that file name does not end with _ameta
if [[ ${input:(-6):6} == "_ameta" ]]; then
echo "Found a file/directory name which ends with _ameta"
echo " $input"
echo ""
echo "Please rename this file as it will mix up a the metadata management of a-put"
exit 1
fi
file_path=$(abspath $input)
if [[ $silent -eq 0 ]] ; then
echo "Checking total size of $input. Please wait."
fi
tot_size=$(du -s $input | cut -f1)
(( cumulative_size = cumulative_size + tot_size ))
#echo $tot_size
#tmp file name. Depends on compression and if file is a directory
if [ $tmp_file == "not_defined" ]
then
if [[ $(file -b "$input" | grep -c directory ) -ne 1 ]]
then
if [[ $compression -eq 1 ]]; then
tmp_file=($(basename "$input" | tr " " "_" )".zst")
else
tmp_file=($(basename "$input" | tr " " "_" ))
fi
else
if [[ $compression -eq 1 ]]; then
tmp_file=($(basename "$input" | tr " " "_" )".tar.zst")
else
tmp_file=($(basename "$input" | tr " " "_" )".tar")
#This tires to fix a situation where a directory contains both subdirectory and correspondig tar file
if [[ -e "${input}.tar" ]]; then
tmp_file=($(basename "$input" | tr " " "_" )"_a-put_.tar")
fi
fi
fi
tmp_file=$(remove_slash_from_ends $tmp_file)
else
if [[ $(file -b "$input" | grep -c directory ) -ne 1 ]]
then
if [[ $compression -eq 1 ]]; then
if [[ ${tmp_file: -4} != ".zst" ]]; then
tmp_file="${tmp_file}.zst"
fi
fi
else
if [[ $compression -eq 1 ]]; then
if [[ ${tmp_file: -8} != ".tar.zst" ]]; then
tmp_file="${tmp_file}.tar.zst"
fi
else
if [[ ${tmp_file: -4} != ".tar" ]]; then
tmp_file="${tmp_file}.tar"
fi
fi
tmp_file=$(remove_slash_from_ends $tmp_file)
fi
fi
# encryption name includes gpg
if [[ $encrypt == "gpg" ]];then
tmp_file="${tmp_file}.gpg"
fi
# encryption name includes c4gh
if [[ $encrypt == "crypt4gh" ]];then
tmp_file="${tmp_file}.c4gh"
if [[ $sdx -eq 0 ]]; then
if [[ $all_keys == "" ]];then
echo "Encryption key not defined"
echo "Use option --public-key to define the encryption key"
exit
fi
else
# Create key for sdx encryption
echo "-----BEGIN CRYPT4GH PUBLIC KEY-----
dmku3fKA/wrOpWntUTkkoQvknjZDisdmSwU4oFk/on0=
-----END CRYPT4GH PUBLIC KEY-----" > $tmp_dir/.sdx_key_tmp_$$
fi
fi
# #SD connect case
# if [[ $sdc --eq 1 ]];then
# tmp_file="${tmp_file}.c4gh"
# fi
#In case of asis-upload, partial_path is the relative path
if [[ $asis_mode -eq 1 ]]; then
partial_path=$(dirname $input )
partial_path=$(remove_slash_from_ends $partial_path)
if [[ $partial_path == "." ]]; then
partial_path=""
fi
if [[ $silent -eq 0 ]] ; then
(( fnum = fnum + 1 ))
echo "$fnum/$num_to_import"
fi
fi
#Tarkista ollaanko koti vai työhakemistossa ja valitse ämpäri
#sen perusteella
project_label=$(echo ${os_project_name} | sed -e s/"project_"/""/g)
# Default bucket for sdx mode
if [[ $sdx -eq 1 || $sdc -eq 1 ]]; then
if [[ $bucket_name == "not_defined" ]]; then
bucket_name=("${project_label}-SD_CONNECT")
fi
fi
if [[ $bucket_name == "not_defined" ]]; then
#default
bucket_name=("${user}-${project_label}-MISC")
## Puhti and Mahti
# In Puhti and Mahti we check if puhti-project and Allas project match
#Puhti scratch
if [ $(echo $file_path | cut -c1-8) == "/scratch" ]
then
puhti_project=$(echo $file_path/ |awk -F "/" '{print $3}')
if [[ $mode == "lumi" ]]; then
puhti_project=$(echo $file_path/ |awk -F "/" '{print $3}' | awk -F "_" '{print $2}')
else
puhti_project=$(echo $file_path/ |awk -F "/" '{print $3}')
fi
bucket_name=("${project_label}-${local_host}-SCRATCH")
if [[ $os_project_name != $puhti_project ]] && [[ $user_answer != "y" ]] ; then
echo ""
echo "NOTE: data locates in Scratch area of project: $puhti_project"
echo "But it will be stored to $storage_name under project: $os_project_name"
echo "Bucket to be used is: $bucket_name"
echo ""
echo "Is this OK (y/n)?"
read user_answer
if [[ $user_answer != "y" ]]; then
echo "Exiting, data not uploaded."
exit 0
fi
fi
partial_path=$(dirname $file_path | sed -e s/"\/scratch\/$puhti_project"/""/g)
fi
#FMI Puhti scratch
if [ $(echo $file_path | cut -c1-12) == "/fmi/scratch" ]
then
puhti_project=$(echo $file_path/ |awk -F "/" '{print $4}')
bucket_name=("${project_label}-${local_host}-SCRATCH")
if [[ $os_project_name != $puhti_project ]] && [[ $user_answer != "y" ]] ; then
echo ""
echo "NOTE: data locates in Scratch area of project: $puhti_project"
echo "But it will be stored to $storage_name under project: $os_project_name"
echo "Bucket to be used is: $bucket_name"
echo ""
echo "Is this OK (y/n)?"
read user_answer
if [[ $user_answer != "y" ]]; then
echo "Exiting, data not uploaded."
exit 0
fi
fi
partial_path=$(dirname $file_path | sed -e s/"\/fmi\/scratch\/$puhti_project"/""/g)
fi
#Puhti and Mahti projappl
if [ $(echo $file_path | cut -c1-9) == "/projappl" ]
then
puhti_project=$(echo $file_path/ |awk -F "/" '{print $3}')
bucket_name=("${project_label}-${local_host}-PROJAPPL")
if [[ $os_project_name != $puhti_project ]] && [[ $user_answer != "y" ]] ; then
echo ""
echo "NOTE: data locates in ProjAppl area of project: $puhti_project"
echo "But it will be stored to $storage_name under project: $os_project_name"
echo "Bucket to be used is: $bucket_name"
echo "Is this OK (y/n)?"
read user_answer
if [[ $user_answer != "y" ]]; then
echo "Exiting, data not uploaded."
exit 0
fi
fi
partial_path=$(dirname $file_path | sed -e s/"\/projappl\/$puhti_project"/""/g)
fi
#Lumi project
if [ $(echo $file_path | cut -c1-8) == "/project" ]
then
puhti_project=$(echo $file_path/ |awk -F "/" '{print $3}'| awk -F "_" '{print $2}')
bucket_name=("${project_label}-${local_host}-project")
if [[ $os_project_name != $puhti_project ]] && [[ $user_answer != "y" ]] ; then
echo ""
echo "NOTE: data locates in Project area of project: $puhti_project"
echo "But it will be stored to ${storage_server} under project: $os_project_name"
echo "Bucket to be used is: $bucket_name"
echo "Is this OK (y/n)?"
read user_answer
if [[ $user_answer != "y" ]]; then
echo "Exiting, data not uploaded."
exit 0
fi
fi
partial_path=$(dirname $file_path | sed -e s/"\/project\/$puhti_project"/""/g)
fi
#Lumi flash
if [ $(echo $file_path | cut -c1-6) == "/flash" ]
then
puhti_project=$(echo $file_path/ |awk -F "/" '{print $3}'| awk -F "_" '{print $2}')
bucket_name=("${project_label}-${local_host}-flash")
if [[ $os_project_name != $puhti_project ]] && [[ $user_answer != "y" ]] ; then
echo ""
echo "NOTE: data locates in Project area of project: $puhti_project"
echo "But it will be stored to ${storage_server} under project: $os_project_name"
echo "Bucket to be used is: $bucket_name"
echo "Is this OK (y/n)?"
read user_answer
if [[ $user_answer != "y" ]]; then
echo "Exiting, data not uploaded."
exit 0
fi
fi
partial_path=$(dirname $file_path | sed -e s/"\/flash\/$puhti_project"/""/g)
fi
#Puhti FMI-projappl
if [ $(echo $file_path | cut -c1-13) == "/fmi/projappl" ]
then
puhti_project=$(echo $file_path/ |awk -F "/" '{print $4}')
bucket_name=("${project_label}-${local_host}-PROJAPPL")
if [[ $os_project_name != $puhti_project ]] && [[ $user_answer != "y" ]] ; then
echo ""
echo "NOTE: data locates in ProjAppl area of project: $puhti_project"
echo "But it will be stored to $storage_name under project: $os_project_name"
echo "Bucket to be used is: $bucket_name"
echo "Is this OK (y/n)?"
read user_answer
if [[ $user_answer != "y" ]]; then
echo "Exiting, data not uploaded."
exit 0
fi
fi
partial_path=$(dirname $file_path | sed -e s/"\/fmi\/projappl\/$puhti_project"/""/g)
fi
#Puhti-NVME disk area
if [ $(echo $file_path | cut -c1-9) == "/run/nvme" ]
then
puhti_project=$SLURM_JOB_ACCOUNT
bucket_name=("${project_label}-${local_host}-LOCAL_SCRATCH")
if [[ $os_project_name != $puhti_project ]] && [[ $user_answer != "y" ]] ; then
echo ""
echo "NOTE: data locates in LOCAL_SCRATCH area of project: $puhti_project"
echo "But it will be stored to $storage_name under project: $os_project_name"
echo "Bucket to be used is: $bucket_name"
echo "Is this OK (y/n)?"
read user_answer
if [[ $user_answer != "y" ]]; then
echo "Exiting, data not uploaded."
exit 0
fi
fi
partial_path=$(dirname $file_path | sed -e s/"\/run\/nvme\/job_$SLURM_JOB_ID\/data"/""/g)
fi
partial_path=$(remove_slash_from_ends $partial_path)
fi
#the name of the object to be created
if [[ $partial_path == "" ]]; then
target_location="${bucket_name}/${tmp_file}"
else
target_location="${bucket_name}/${partial_path}/$tmp_file"
fi
if [[ $sdc -eq 1 ]]; then
target_location="${target_location}.c4gh"
fi
#Check if the object already exists
target_exists=0
#echo "rclone ls ${storage_server}:${target_location}"
if [[ $(rclone ls ${storage_server}:${target_location} 2> /dev/null | wc -c) -gt 0 ]]; then
target_exists=1
fi
if [[ $check_mode -eq 0 ]]; then
if [[ $target_exists -eq 1 ]]; then
if [[ $override_mode -eq 1 ]]; then
# in override mode explicitly delete the old object
rclone delete ${storage_server}:${target_location}
else
echo ""
echo "A file/directory with the same name has already been uploaded into"
echo "bucket $bucket_name in $storage_server"
echo ""
echo " ${target_location} "
echo ""
echo "Remove the old object if you wish to upload a new version of $input to $storage_server."
echo "You can add option: --override to your command line, if you want to overwrite the object already existing in $storage_name."
echo "Alternatively, you can define a different bucket name using the option --bucket "
echo "or define different object name with the option --object"
exit 1
fi
fi
fi
#collect and count metadata
ameta_file="${tmp_dir}/${tmp_file}_ameta"
if [[ $sdc -eq 1 ]]; then
ameta_file="${tmp_dir}/${tmp_file}.c4gh_ameta"
fi
echo "user: $user" >> "${ameta_file}"
echo "host: $(hostname)" >> "${ameta_file}"
echo "host_name: $local_host" >> "${ameta_file}"
echo "input: $input" >> "${ameta_file}"
echo "original_location: $file_path " >> "${ameta_file}"
if [[ $mode == "s3cmd" ]] || [[ $mode == "lumi" ]]; then
echo "protocol: S3 " >> "${ameta_file}"
else
echo "protocol: swift" >> "${ameta_file}"
fi
if [[ $compression -eq 1 ]]; then
echo "compression: zstd" >> "${ameta_file}"
else
echo "compression: none" >> "${ameta_file}"
fi
if [[ $encrypt == "gpg" ]]; then
gpg_version="$(gpg --version |head -2 | tr "\n" " ")"
echo "encryption: $gpg_version AES256" >> "${ameta_file}"
fi
if [[ $encrypt == "crypt4gh" ]]; then
crypt4gh_version="$(crypt4gh -v)"
echo "encryption: $crypt4gh_version" >> "${ameta_file}"
fi
if [[ $sdx -eq 1 ]]; then
echo "sd_connect: yes" >> "${ameta_file}"
fi
if [[ $sdc -eq 1 ]]; then
echo "sd-lock: ${target_location}" >> "${ameta_file}"
fi
if [[ $meta_message != "" ]]; then
echo "Note: $meta_message" >> "${ameta_file}"
fi
num_files=0
#initial check of file or directory count
if [[ $filelist_level -lt 2 ]] ; then
num_check=$(find "$input" -type f | wc -l )
if [[ $num_check -gt $max_files ]]; then
echo ""
echo "Refusing to process the data."
echo " "
echo "$input contains $num_check directories or files."
echo "Collecting information about all these items would take too long time"
echo ""
echo "Try uploading subdirectories of $input:"
echo ""
echo " cd $input"
echo " a-put * "
echo " "
echo "or use option --skip-filelist skip file list collection to metadata"
echo " a-put --skip-filelist * "
exit 1
fi
num_files=$num_check
#Print file list
if [[ $num_check -gt 0 ]]; then
#echo "find "$input" -type f -print0 | xargs -0 ls -l"
find "$input" -type f -print0 | xargs -0 ls -l >> "${ameta_file}"
else
echo "Empty directory" >> "${ameta_file}"
fi
else
num_files="unknown_number"
echo "File listing skipped with --skip-filelist option." >> "${ameta_file}"
fi
#check if there is enough space for temporary data
if [[ $tot_size -gt $max_size ]]
then
echo "This file or directory is too big for this tool"
echo "Total size: ${tot_size}K"
echo "Please use swift or rclone command to upload the data to allas"
rm -f "${ameta_file}"
clean_temp_dir
exit 1
fi
echo ""
if [[ $tot_size -gt $free_space ]] && [[ $compression -eq 1 ]]
then
echo "It looks like that there is not enough space for the temporary files."
echo "$input contains $num_files files or directories that take ${tot_size}K of disk space"
echo "Available free space is ${free_space}K"
echo ""
echo "a-put often fails when it tries to check the available free space in WRKDIR or scratch directories."
echo "If you are sure that you have enough space in WRKDIR or scratch, you can skip this check by adding"
echo "option -x to your a-put command"
echo ""
echo "If you don't have enough free space, upload some data from WRKDIR/scratch with using option --nc."
echo "With --nc option, data is not compressed and thus temporary storage space is not needed."
rm -f "${ameta_file}"
clean_temp_dir
exit 1
fi
if [[ $silent -eq 0 ]];then
echo "$input contains $num_files files or directories that take ${tot_size}K of disk space"
fi
packing_failed=0
#Pakkaaminen