diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 28b694a..4f54052 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -21,22 +21,17 @@ SERVICE_NAME="pg_backup" send_loki_status() { local status="$1" local timestamp_ns=$(date +%s%N) - echo "{ - \"streams\": [ - { - \"stream\": { \"service_name\": \"$SERVICE_NAME\" }, - \"values\": [ - [ \"$timestamp_ns\", \"$status\" ] - ] - } - ] - }" - curl -H "Content-Type: application/json" \ + local level="info" + if [ "$status" = "failed" ]; then + level="error" + fi + + curl -v -H "Content-Type: application/json" \ -s -X POST "$LOKI_URL" \ --data-raw "{ \"streams\": [ { - \"stream\": { \"service_name\": \"$SERVICE_NAME\" }, + \"stream\": { \"service_name\": \"$SERVICE_NAME\", \"level\": \"$level\" }, \"values\": [ [ \"$timestamp_ns\", \"$status\" ] ] @@ -49,6 +44,6 @@ trap 'send_loki_status failed' ERR PGPASSWORD=${POSTGRES_PASSWORD} pg_basebackup -h "${POSTGRES_HOST}" -d "sslmode=${POSTGRES_SSL_MODE}" -D /tmp/backup -U ${POSTGRES_USER} -F t -z -P restic --verbose backup -H ${RESTIC_HOST} --tag ${RESTIC_TAG} /tmp/backup -restic forget --prune --keep-last 14 --host ${RESTIC_HOST} +restic forget --prune --keep-within 14d --host ${RESTIC_HOST} send_loki_status "done"