-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·63 lines (45 loc) · 1.52 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
log_execution() {
name="$1"; shift
echo "$(date -I'seconds'): $name - starting" | tee -a state/event-log.log >> /dev/stderr
"$@"
exit_code=$?
echo "$(date -I'seconds'): $name - ended with error code $exit_code" | tee -a state/event-log.log >> /dev/stderr
if [ "$exit_code" -ne 0 ]; then
exit "$exit_code"
fi
}
set -a
[ -f .env ] && . ./.env
set +a
while true; do
mkdir -p state
log_execution 'fetcher' \
./fetcher
rm -rf to-upload
log_execution 'apifier' \
nice ./apifier -output-dir to-upload
log_execution 'uploader' \
./uploader \
-directory to-upload \
-bucket-name "${R2_PUBLIC_BUCKET_NAME:?}"
rm -rf to-upload
log_execution 'sqlite vacuum' \
nice sqlite3 state/repos.db \
"pragma journal_mode=WAL; pragma temp_store_directory='.'; vacuum"
rm -rfv to-upload-backup
mkdir -p to-upload-backup
log_execution 'compressing state.db for a backup upload' \
nice gzip < state/repos.db > to-upload-backup/repos.db.gz
log_execution 'uploading compressed database backup' \
./uploader \
-bucket-name "${R2_DB_BACKUP_BUCKET_NAME:?}" \
-directory to-upload-backup \
-content-type application/x-sqlite3
rm -rfv to-upload-backup
log_execution 'purging the metadata file from cache' \
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_PURGE_CACHE_ZONE:?}/purge_cache" \
-H "Authorization: bearer ${CLOUDFLARE_PURGE_CACHE_TOKEN:?}" \
-H "Content-Type: application/json" \
--data "{\"files\":[\"https://${CLOUDFLARE_PURGE_CACHE_DOMAIN:?}/metadata\"]}"
done