8
8
echo JAVACMD_OPTIONS=\" -server -Xmx$memory \" > ~/.osmosis
9
9
fi
10
10
11
- workingDirectory=" /mnt/data/data"
11
+ workingDirectory=" /mnt/data"
12
+ mkdir -p $workingDirectory
12
13
13
14
# Check if state.txt exist in the workingDirectory,
14
15
# in case the file does not exist locally and does not exist in the cloud the replication will start from 0
15
16
if [ ! -f $workingDirectory /state.txt ]; then
16
17
echo " File $workingDirectory /state.txt does not exist"
17
- echo " let's get check the cloud "
18
+ # ## AWS
18
19
if [ $CLOUDPROVIDER == " aws" ]; then
19
- aws s3 ls $AWS_S3_BUCKET$REPLICATION_FOLDER /state.txt
20
+ aws s3 ls $AWS_S3_BUCKET / $REPLICATION_FOLDER /state.txt
20
21
if [[ $? -eq 0 ]]; then
21
- echo " File exist, let's get it"
22
- aws s3 cp $AWS_S3_BUCKET$REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
22
+ echo " File exist, let's get it from $CLOUDPROVIDER - $AWS_S3_BUCKET "
23
+ aws s3 cp $AWS_S3_BUCKET / $REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
23
24
fi
24
25
fi
26
+
27
+ # ## GCP
25
28
if [ $CLOUDPROVIDER == " gcp" ]; then
26
- gsutil ls $GCP_STORAGE_BUCKET$REPLICATION_FOLDER /state.txt
29
+ gsutil ls $GCP_STORAGE_BUCKET / $REPLICATION_FOLDER /state.txt
27
30
if [[ $? -eq 0 ]]; then
28
- echo " File exist, let's get it"
29
- gsutil cp $GCP_STORAGE_BUCKET$REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
31
+ echo " File exist, let's get it from $CLOUDPROVIDER - $GCP_STORAGE_BUCKET "
32
+ gsutil cp $GCP_STORAGE_BUCKET / $REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
30
33
fi
31
34
fi
32
- # In case the state.txt does not exist anywhere, lets create the folder data.
33
- mkdir -p $workingDirectory
35
+
36
+ # ## Azure
37
+ if [ $CLOUDPROVIDER == " azure" ]; then
38
+ state_file_exists=$( az storage blob exists --container-name $AZURE_CONTAINER_NAME --name $REPLICATION_FOLDER /state.txt --query=" exists" )
39
+ if [[ $state_file_exists == " true" ]]; then
40
+ echo " File exist, let's get it from $CLOUDPROVIDER - $AZURE_CONTAINER_NAME "
41
+ az storage blob download \
42
+ --container-name $AZURE_CONTAINER_NAME \
43
+ --name $REPLICATION_FOLDER /state.txt \
44
+ --file $workingDirectory /state.txt --query=" name"
45
+ fi
46
+ fi
47
+ mkdir -p $workingDirectory
34
48
fi
35
49
36
50
# Creating the replication files
37
- function generateReplication () {
51
+ function generateReplication() {
38
52
osmosis -q \
39
53
--replicate-apidb \
40
54
iterations=0 \
@@ -48,17 +62,31 @@ function generateReplication () {
48
62
--write-replication \
49
63
workingDirectory=$workingDirectory &
50
64
while true ; do
51
- for file in $( find $workingDirectory / -cmin -1) ; do
52
- if [ -f " $file " ]; then
53
- bucketFile=${file#* " $workingDirectory " }
54
- echo $( date +%F_%H:%M:%S) " : New files..." $file
55
- # AWS
65
+ for local_file in $( find $workingDirectory / -cmin -1) ; do
66
+ if [ -f " $local_file " ]; then
67
+
68
+ cloud_file=$REPLICATION_FOLDER /${local_file#* " $workingDirectory /" }
69
+ echo $( date +%F_%H:%M:%S) " : Copy file...$local_file to $cloud_file "
70
+
71
+ # ## AWS
56
72
if [ $CLOUDPROVIDER == " aws" ]; then
57
- aws s3 cp $file $AWS_S3_BUCKET$REPLICATION_FOLDER$bucketFile --acl public-read
73
+ aws s3 cp $local_file $AWS_S3_BUCKET / $cloud_file --acl public-read
58
74
fi
59
- # Google Storage
75
+
76
+ # ## GCP
60
77
if [ $CLOUDPROVIDER == " gcp" ]; then
61
- gsutil cp -a public-read $file $GCP_STORAGE_BUCKET$REPLICATION_FOLDER$bucketFile
78
+ # TODO, emable public acces
79
+ gsutil cp -a public-read $local_file $GCP_STORAGE_BUCKET /$cloud_file
80
+ fi
81
+
82
+ # ## Azure
83
+ if [ $CLOUDPROVIDER == " azure" ]; then
84
+ # TODO, emable public acces
85
+ az storage blob upload \
86
+ --container-name $AZURE_CONTAINER_NAME \
87
+ --file $local_file \
88
+ --name $cloud_file \
89
+ --output none
62
90
fi
63
91
fi
64
92
done
@@ -69,8 +97,8 @@ function generateReplication () {
69
97
# Check if Postgres is ready
70
98
flag=true
71
99
while " $flag " = true ; do
72
- pg_isready -h $POSTGRES_HOST -p 5432 > /dev/null 2>&2 || continue
73
- # Change flag to false to stop ping the DB
74
- flag=false
75
- generateReplication
76
- done
100
+ pg_isready -h $POSTGRES_HOST -p 5432 > /dev/null 2>&2 || continue
101
+ # Change flag to false to stop ping the DB
102
+ flag=false
103
+ generateReplication
104
+ done
0 commit comments