-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·45 lines (32 loc) · 954 Bytes
/
run.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
#!/usr/bin/env bash
set -e
BUCKET_PATH="$(echo "$1" | sed 's#s3://##' | tr -s '/' | sed 's#/$##')"
[ -n "$BUCKET_PATH" ] || (>&2 echo 'bucket/path is required'; exit 1)
[ ! -f 'logs/sync.log' ] || (>&2 echo 'logs/sync.log exists'; exit 2)
function timer() {
local start_time=$(date +%s)
"$@"
local elapsed_seconds="$(($(date +%s) - $start_time))"
echo "Total time elapsed: $(seconds_format "$elapsed_seconds") (HH:MM:SS)"
}
function seconds_format_gnu() {
date -u -d "@$1" +%T
}
function seconds_format_mac() {
date -u -j -f "%s" "$1" +%T
}
function seconds_format() {
(seconds_format_gnu "$1" || seconds_format_mac "$1") 2>/dev/null
}
function sync() {
docker compose exec s3fs aws s3 sync /mnt/ \
"s3://$BUCKET_PATH/" \
--exclude "*/tables/teacher/tulsa_model/*"
}
function main() {
date ; echo
sync ; echo
date ; echo
}
timer main | tee logs/sync.log
mv logs/sync.log "logs/sync-$(date '+%Y%m%d%H%M%S').log"