add status and curl verbose

This commit is contained in:
2025-05-11 18:48:57 +03:00
parent 9bb15825b1
commit 63e8751414

View File

@@ -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"