Skip to content

Commit

Permalink
bypass-lock for "list" and "info" to prevent errors from metrics
Browse files Browse the repository at this point in the history
temporary workaround for borgbackup/borg#7255 as cache is still locked
  • Loading branch information
spali committed Oct 3, 2024
1 parent 263ca16 commit 4b1f98f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=protected-access
import json
import os
import subprocess
from typing import Any

Expand Down Expand Up @@ -71,9 +72,9 @@ def set_metric(
def collect(borgmatic_configs: list, registry):
borgmatic_configs = " -c ".join(borgmatic_configs)
# Overall repo info and last archive only
repos = run_command(f"borgmatic info -c {borgmatic_configs} --json --last 1")
repos = run_command(f"borgmatic info --bypass-lock -c {borgmatic_configs} --json --last 1")
# All archives
archives = run_command(f"borgmatic list -c {borgmatic_configs} --json")
archives = run_command(f"borgmatic list --bypass-lock -c {borgmatic_configs} --json")

for r, a in zip(repos, archives):
labels = {"repository": r["repository"]["location"]}
Expand Down Expand Up @@ -144,10 +145,15 @@ def run_command(command: str) -> dict:
Execute command via the command line and load the output into dictionary.
"""
with timy.Timer(command):
# temporary workaround for https://github.com/borgbackup/borg/issues/7255
tmp_env=os.environ.copy()
tmp_env["HOME"]="/tmp/borgmatic-exporter-cache"
tmp_env["BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK"]="yes"
result = subprocess.run(
command.split(" "),
check=True,
stdout=subprocess.PIPE,
env=tmp_env
)
output = result.stdout.decode("utf-8").strip()
return json.loads(output)

0 comments on commit 4b1f98f

Please sign in to comment.