resticprofile

一、安装

1.1 Linux

export version=0.32.0
# 下载 .tar.gz 压缩包并解压缩
wget https://github.com/creativeprojects/resticprofile/releases/download/v${version}/resticprofile_${version}_linux_amd64.tar.gz
tar -xzvf resticprofile_${version}_linux_amd64.tar.gz resticprofile
# 使用软链接管理可执行二进制文件
mv resticprofile ~/bin/resticprofile_${version}_linux_amd64
sudo ln -s ~/bin/resticprofile_${version}_linux_amd64 /usr/local/bin/resticprofile
# 删除下载的压缩包
rm resticprofile_${version}_linux_amd64.tar.gz

1.2 Windows

scoop install resticprofile

二、配置

2.1 配置 resticprofile 自动补全

sudo -i
resticprofile generate --bash-completion > /etc/bash_completion.d/resticprofile
chmod +x /etc/bash_completion.d/resticprofile

三、使用

k1rinh/resticprofile

/guide/backup-data-with-restic/

常用命令

# 列出所有配置文件内容
resticprofile -c ./main.yaml
# 查看特定服务(如 vaultwarden)的配置详情
resticprofile -c ./main.yaml -n vaultwarden show
# 不运行 restic 命令,而是显示命令行
resticprofile -c ./main.yaml -n vaultwarden --dry-run backup
# 运行 restic 命令,但不写入仓库
resticprofile -c ./main.yaml -n vaultwarden backup --dry-run
# 正常运行 restic 命令
resticprofile -c ./main.yaml -n vaultwarden backup
# 设置计划任务
resticprofile -c ./main.yaml -n vaultwarden schedule
# 取消设置计划任务
resticprofile -c ./main.yaml -n vaultwarden unschedule

注意事项

设置和使用环境变量

resticprofile 支持两种变量:一种是特有的模板变量 {{ .Profile.Name }},在解析配置前被替换;一种是通用的运行时变量 ${HOME},在执行 restic 命令前被替换,在解析配置时保持原样。

配置的 envenv-file 中设置的环境变量,只能通过运行时变量 ${Varname} 调用,不能通过模板变量 {{ .Env.Varname }} 调用。

https://creativeprojects.github.io/resticprofile/configuration/variables/index.html

预定义变量

  • {{ .Profile.Name }} 当前配置文件的名称。
  • {{ .Env.{NAME} }} 现有环境变量 ${NAME}(不包含刚用 env 导入的环境变量)。
  • {{ .Env.HOME }} 类 Unix 系统的用户家目录。
  • {{ .Env.USERPROFILE }} Windows 系统的用户家目录。

https://creativeprojects.github.io/resticprofile/configuration/variables/index.html#pre-defined-variables

使用 template 功能

在调用 template 时,不会管前面的缩进,下面两个的效果一模一样。

  {{ template "retention-policy" . }}
{{ template "retention-policy" . }}

所以使用 .yaml 作为配置文件时,需要在设置 template 时进行相应的缩进。