-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmortar-daily-export.sh
executable file
·82 lines (71 loc) · 2.06 KB
/
mortar-daily-export.sh
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
#!/bin/bash
# Script to mongoexport all collections that Mortar needs to run our recommended system,
# then upload them to S3
export date=$(date +%Y-%m-%d)
echo "Starting run for $date"
# cleanup old export folders
for dir in $(find . -maxdepth 1 -name '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]' -type d)
do
# only remove export files from earlier dates
if [ $(basename $dir) \< $date ]
then
echo "Removing old export folder $dir"
bash -c "set -x; rm -rf $dir"
fi
done
export folderForDate="./$date"
completionFile="$date-complete.txt"
completionFileFullPath="$folderForDate/$completionFile"
# if the completion file already exists, we've already run for the current date, so exit
if [ -e $completionFileFullPath ]
then
echo "Completion file $completionFile already exists"
echo "Upload and export for $date already done"
exit
fi
if [ ! -d ${folderForDate} ]
then
echo "Creating folder $folderForDate"
mkdir "$folderForDate"
fi
collections=("frames" "users" "videos")
# start export and upload jobs for all collections in parallel
for collection in ${collections[@]}
do
echo "Starting $collection"
pidVar="${collection}Pid"
./mongo-export-upload.sh -c ${collection} 1>${folderForDate}/${collection}-export.log 2>&1 &
export ${pidVar}=$!
done
# wait for all jobs to finish
for collection in ${collections[@]}
do
pidVar="${collection}Pid"
statusVar="${collection}Status"
wait ${!pidVar}
export ${statusVar}=$?
done
echo "All jobs done"
finalStatus=0
# report on success or failre of all jobs
for collection in ${collections[@]}
do
statusVar="${collection}Status"
echo "$collection returned status ${!statusVar}"
if [ ${!statusVar} -ne 0 ]
then
finalStatus=1
fi
done
if [ $finalStatus -eq 0 ]
then
# if we succeed create a file and upload it that signals mortar we completed successfully
set -e
echo "Creating completion file $completionFile"
echo "1" > $completionFileFullPath
echo "Uploading completion file $completionFile"
s3cmd --progress put $completionFileFullPath s3://dev-shelby-mortar-share/input/
exit 0
else
exit 1
fi