start.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. ssh_config_path = Path.home() / ".ssh"
  12. volumes = [
  13. f"{config_path}:/etc/borgmatic.d/",
  14. f"{ssh_config_path}:/root/.ssh",
  15. "borg_config:/root/.config/borg",
  16. "borg_cache:/root/.cache/borg",
  17. "borgmatic_state:/root/.local/state/borgmatic",
  18. ]
  19. if ssh_auth_sock:
  20. volumes += [f"{ssh_auth_sock}:{ssh_auth_sock}:Z"]
  21. volume_args = [a for vol in volumes for a in ["-v", vol]]
  22. image_name = "ghcr.io/borgmatic-collective/borgmatic"
  23. args = [
  24. "podman",
  25. "run",
  26. "-h",
  27. hostname,
  28. "--detach",
  29. "--name",
  30. container_name,
  31. "-e SSH_AUTH_SOCK",
  32. "-e TZ=Europe/Paris",
  33. "--security-opt=label=disable"
  34. ] + volume_args + [image_name]
  35. print(args)
  36. subprocess.run(args)
  37. if __name__ == "__main__":
  38. main()