Skip to content

Commit 7550a17

Browse files
committed
Switching to periodic backup via a sleep
1 parent 19504e0 commit 7550a17

2 files changed

Lines changed: 89 additions & 79 deletions

File tree

nomad-jobs/codinggrace.nomad

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@ EOF
141141
interval = "10s"
142142
timeout = "2s"
143143
}
144-
check {
145-
name = "alive"
146-
type = "tcp"
147-
interval = "10s"
148-
timeout = "2s"
149-
}
150144
}
151145

152146
resources {
@@ -186,4 +180,93 @@ EOF
186180
}
187181
}
188182
}
183+
184+
group "backup" {
185+
count = 1
186+
187+
ephemeral_disk {
188+
size = 100
189+
}
190+
191+
task "codinggrace-periodic-backup" {
192+
driver = "docker"
193+
config {
194+
image = "gitlab.twomeylee.name:7443/twomeylee/postgresql-backup:build-268"
195+
command = "/bin/bash"
196+
args = ["${NOMAD_TASK_DIR}/main.sh"]
197+
}
198+
199+
logs {
200+
max_files = 2
201+
max_file_size = 15
202+
}
203+
204+
resources {
205+
memory = 256
206+
}
207+
208+
template {
209+
destination = "${NOMAD_TASK_DIR}/backup.sh"
210+
data = <<EOF
211+
#!/bin/bash
212+
213+
set -xeuo pipefail
214+
215+
{{if service "codinggrace-postgresql@scaleway"}}
216+
{{with index (service "codinggrace-postgresql@scaleway") 0}}
217+
export POSTGRES_HOSTNAME="{{.Address}}"
218+
export POSTGRES_PORT="{{.Port}}"
219+
{{end}}
220+
{{end}}
221+
222+
export POSTGRES_DB="{{key "codinggrace/prod/postgresql/db"}}"
223+
export POSTGRES_USER="{{key "codinggrace/prod/postgresql/user"}}"
224+
export POSTGRES_PASSWORD="{{key "codinggrace/prod/postgresql/password"}}"
225+
226+
export AWS_ACCESS_KEY_ID="{{key "postgresql-backups/aws_access_key_id"}}"
227+
export AWS_SECRET_ACCESS_KEY="{{key "postgresql-backups/aws_secret_access_key"}}"
228+
export S3_BUCKET="{{key "postgresql-backups/bucket"}}"
229+
export S3_PREFIX="codinggrace/"
230+
export S3_FILENAME="codinggrace"
231+
232+
exec /usr/local/bin/backup
233+
EOF
234+
}
235+
236+
template {
237+
destination = "${NOMAD_TASK_DIR}/main.sh"
238+
perms = 755
239+
data = <<EOF
240+
#!/bin/bash
241+
242+
set -xeuo pipefail
243+
244+
function main {
245+
target_time="01:00"
246+
247+
current_epoch=$(date +%s)
248+
target_epoch_short=$(date --date="$target_time" +%s)
249+
sleep_seconds_short=$(( $target_epoch_short - $current_epoch ))
250+
target_epoch_long=$(date --date="$target_time tomorrow" +%s)
251+
sleep_seconds_long=$(( $target_epoch_long - $current_epoch ))
252+
253+
if (( $sleep_seconds_short > 0 )); then
254+
sleep $sleep_seconds_short;
255+
else
256+
sleep $sleep_seconds_long;
257+
fi
258+
259+
bash ${NOMAD_TASK_DIR}/backup.sh
260+
}
261+
262+
while :
263+
do
264+
main;
265+
done
266+
267+
EOF
268+
}
269+
270+
}
271+
}
189272
}

nomad-jobs/codinggrace_backup.nomad

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)