ngosang / restic-exporter

Prometheus exporter for the Restic backup system
MIT License
79 stars 17 forks source link

Add support for sftp.command #31

Open farcaller opened 3 months ago

farcaller commented 3 months ago

Please add support for passing extra options to restic, e.g. -o sftp.command=... in case the sftp backend with a custom private key is used.

m00n commented 1 month ago

fyi, depending on what you need this works out of the box if you mount some ssh config into your container

docker-compose.yml

services:
  restic-exporter:                                                                                                                                                                                                                                                                                               
    image: ngosang/restic-exporter                                                                                                                                                                                                                                                                               
    container_name: restic-exporter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
    env_file:                                                                                                                                                                                                                                                                                                    
      - restic-exporter.env                                                                                                                                                                                                                                                                                      
    volumes:                                                                                                                                                                                                                                                                                                     
      - ./restic-exporter/ssh/config:/root/.ssh/config                                                                                                                                                                                                                                                           
      - ./restic-exporter/ssh/known_hosts:/root/.ssh/known_hosts                                                                                                                                                                                                                                                 
      - ./restic-exporter/ssh/id_rsa:/root/restic/id_rsa                                                                                                                                                                                                                                   
    expose:                                                                                                                                                                                                                                                                                                      
      - 8001                                                                                                                                                                                                                                                                                                     
    restart: unless-stopped 

Create a SSH config for your sftp restic host, like this

SSH config file

Host restic-backup
        User your-user
        HostName example.com
        IdentityFile /path/to/id_rsa
        ServerAliveInterval 60
        ServerAliveCountMax 240

And you need the entry for your sftp host in the known_hosts file, otherwise the exporter fails because the host key can not be verified.