
ngosang/restic-exporterDocker镜像源代码:GitHub
Restic备份系统的Prometheus导出器。
该镜像提供Restic备份系统的Prometheus指标导出功能,可监控Restic仓库的关键状态,如备份检查结果、快照数量、备份时间戳、文件总数、备份大小等。支持多种存储后端(本地、REST Server、Amazon S3、Backblaze B2等),适用于需要对Restic备份进行可视化监控和告警的场景。
restic check)该镜像支持以下架构:
镜像可从GHCR或DockerHub拉取:
bash# 从GHCR拉取 docker pull ghcr.io/ngosang/restic-exporter # 或从DockerHub拉取 docker pull ngosang/restic-exporter
兼容docker-compose v2架构:
yaml--- version: '2.1' services: restic-exporter: image: ngosang/restic-exporter container_name: restic-exporter environment: - TZ=Europe/Madrid # 时区 - RESTIC_REPOSITORY=/data # Restic仓库路径或URL - RESTIC_PASSWORD=<password_here> # 仓库密码(明文) # - RESTIC_PASSWORD_FILE=</file_with_password_here> # 密码文件路径(二选一) - REFRESH_INTERVAL=1800 # 指标刷新间隔(秒,默认60) volumes: - /host_path/restic/data:/data # 挂载本地仓库路径(如使用本地后端) ports: - "8001:8001" # 默认监听端口 restart: unless-stopped
bashdocker run -d \ --name=restic-exporter \ -e TZ=Europe/Madrid \ -e RESTIC_REPOSITORY=/data \ -e RESTIC_PASSWORD=<password_here> \ -e REFRESH_INTERVAL=1800 \ -p 8001:8001 \ --restart unless-stopped \ ngosang/restic-exporter
所有配置通过环境变量实现,支持Restic的所有后端,部分后端需额外配置密钥。
| 变量名 | 说明 | 示例 |
|---|---|---|
RESTIC_REPOSITORY | Restic仓库URL,支持所有后端 | 本地:/data;S3:s3:s3.amazonaws.com/bucket_name;B2:b2:bucketname:path |
RESTIC_PASSWORD | 仓库密码(明文),与RESTIC_PASSWORD_FILE二选一 | mypassword123 |
RESTIC_PASSWORD_FILE | 密码文件路径(需挂载文件到容器内),与RESTIC_PASSWORD二选一 | /restic_password.txt |
REFRESH_INTERVAL | 指标刷新间隔(秒),默认60秒(建议设为较大值,如30分钟=1800秒) | 1800 |
LISTEN_PORT | 监听端口,默认8001 | 8080 |
LISTEN_ADDRESS | 监听地址,默认所有地址 | 127.0.0.1 |
LOG_LEVEL | 日志级别,默认INFO | DEBUG、WARNING、ERROR |
EXIT_ON_ERROR | 遇Restic错误时是否退出,默认False(仅日志记录) | True |
| 后端类型 | 所需环境变量 |
|---|---|
| Amazon S3/Minio/Wasabi | AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY |
| Backblaze B2 | B2_ACCOUNT_ID、B2_ACCOUNT_KEY |
Docker镜像不包含Rclone,若使用Rclone后端(rclone:remote:/path),需挂载主机的Rclone可执行文件和配置文件:
yamlversion: '2.1' services: restic-exporter: image: ngosang/restic-exporter container_name: restic-exporter environment: - TZ=Europe/Madrid - RESTIC_REPOSITORY=rclone:gd-backup:/restic # Rclone远程仓库 - RESTIC_PASSWORD=<password_here> - REFRESH_INTERVAL=1800 volumes: - /usr/bin/rclone:/usr/bin/rclone:ro # 挂载主机Rclone可执行文件 - /host_path/rclone.conf:/root/.config/rclone/rclone.conf:ro # 挂载Rclone配置文件 ports: - "8001:8001" restart: unless-stopped
| 指标名称 | 类型 | 说明 | 示例值 |
|---|---|---|---|
restic_check_success | gauge | restic check操作结果(1=成功,0=失败) | 1.0 |
restic_locks_total | counter | 仓库锁总数 | 1.0 |
restic_snapshots_total | counter | 快照总数 | 100.0 |
restic_backup_timestamp | gauge | 最后备份时间戳 | 1.666273638e+09(带标签:客户端主机名、用户名、快照哈希等) |
restic_backup_files_total | counter | 备份文件总数 | 8.0(带标签:同上) |
restic_backup_size_total | counter | 备份总大小(字节) | 4.3309562e+07(带标签:同上) |
restic_backup_snapshots_total | counter | 快照计数 | 1.0(带标签:同上) |
restic_scrape_duration_seconds | gauge | 指标采集耗时(秒) | 166.9411084651947 |
yamlscrape_configs: - job_name: 'restic-exporter' static_configs: - targets: ['192.168.1.100:8001'] # restic-exporter实例地址
yaml- alert: ResticCheckFailed expr: restic_check_success == 0 for: 5m labels: severity: critical annotations: summary: Restic检查失败(实例 {{ $labels.instance }}) description: Restic仓库检查失败\n VALUE = {{ $value }}\n LABELS = {{ $labels }} - alert: ResticOutdatedBackup expr: time() - restic_backup_timestamp > *** # 15天(***秒) for: 0m labels: severity: critical annotations: summary: Restic {{ $labels.client_hostname }} / {{ $labels.client_username }} 备份过期 description: Restic备份已过期\n VALUE = {{ $value }}\n LABELS = {{ $labels }}
提供参考Grafana仪表盘:grafana_dashboard.json
!Grafana仪表盘
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务