| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import os
- import subprocess
- from pathlib import Path
- def to_volume_string(vol: str):
- return f"-v {vol}:/mnt/source{vol}:ro"
- def main():
- hostname = "host"
- container_name = "borgmatic"
- ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
- config_path = Path.cwd() / "data" / "borgmatic.d"
- credentials_path = Path.cwd() / "data" / "credentials"
- ssh_config_path = Path.home() / ".ssh"
- volumes = [
- f"{config_path}:/etc/borgmatic.d/",
- f"{credentials_path}:/credentials/",
- f"{ssh_config_path}:/root/.ssh",
- "borg_config:/root/.config/borg",
- "borg_cache:/root/.cache/borg",
- "borgmatic_state:/root/.local/state/borgmatic",
- ]
- if ssh_auth_sock:
- volumes += [f"{ssh_auth_sock}:{ssh_auth_sock}:Z"]
- volume_args = [a for vol in volumes for a in ["-v", vol]]
- image_name = "ghcr.io/borgmatic-collective/borgmatic"
- args = [
- "podman",
- "run",
- "-h",
- hostname,
- "--detach",
- "--name",
- container_name,
- "-e SSH_AUTH_SOCK",
- "-e TZ=Europe/Paris",
- "--security-opt=label=disable"
- ] + volume_args + [image_name]
- print(args)
- subprocess.run(args)
- if __name__ == "__main__":
- main()
|