2 Commits
0.0.7 ... 0.0.8

Author SHA1 Message Date
9c2918254c add loki
All checks were successful
Build Docker image / docker (push) Successful in 1m39s
2025-05-11 17:08:04 +03:00
f2cdb2c3f6 update version 2025-05-11 13:47:45 +03:00
2 changed files with 25 additions and 5 deletions

View File

@@ -4,10 +4,6 @@ on:
push:
branches:
- main
workflow_run:
workflows: ["Build Docker image"]
types:
- completed
jobs:
deploy:

View File

@@ -15,6 +15,30 @@ POSTGRES_PORT="${POSTGRES_PORT:-5432}"
POSTGRES_SSL_MODE=${POSTGRES_SSL_MODE:-"require"}
RESTIC_TAG=${RESTIC_TAG:-"pg_basebackup"}
LOKI_URL="http://loki.montoring:3100/loki/api/v1/push"
SERVICE_NAME="pg_backup"
send_loki_status() {
local status="$1"
local timestamp_ns=$(date +%s%N)
curl -H "Content-Type: application/json" \
-s -X POST "$LOKI_URL" \
--data-raw "{
\"streams\": [
{
\"stream\": { \"service_name\": \"$SERVICE_NAME\" },
\"values\": [
[ \"$timestamp_ns\", \"$status\" ]
]
}
]
}"
}
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}
send_loki_status "done"