start.py 1.2 KB

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