start.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import subprocess
  3. from pathlib import Path
  4. def to_volume_string(vol: str):
  5. return f"-v {vol}:/mnt/source{vol}:ro"
  6. def main():
  7. hostname = "host"
  8. container_name = "borgmatic"
  9. ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
  10. config_path = Path.cwd() / "data" / "borgmatic.d"
  11. credentials_path = Path.cwd() / "data" / "credentials"
  12. ssh_config_path = Path.home() / ".ssh"
  13. volumes = [
  14. f"{config_path}:/etc/borgmatic.d/",
  15. f"{credentials_path}:/credentials/",
  16. f"{ssh_config_path}:/root/.ssh",
  17. "borg_config:/root/.config/borg",
  18. "borg_cache:/root/.cache/borg",
  19. "borgmatic_state:/root/.local/state/borgmatic",
  20. ]
  21. if ssh_auth_sock:
  22. volumes += [f"{ssh_auth_sock}:{ssh_auth_sock}:Z"]
  23. volume_args = [a for vol in volumes for a in ["-v", vol]]
  24. image_name = "ghcr.io/borgmatic-collective/borgmatic"
  25. args = [
  26. "podman",
  27. "run",
  28. "-h",
  29. hostname,
  30. "--detach",
  31. "--name",
  32. container_name,
  33. "-e SSH_AUTH_SOCK",
  34. "-e TZ=Europe/Paris",
  35. "--security-opt=label=disable"
  36. ] + volume_args + [image_name]
  37. print(args)
  38. subprocess.run(args)
  39. if __name__ == "__main__":
  40. main()