3 个不稳定版本

0.2.1 2020 年 8 月 23 日
0.1.1 2020 年 5 月 6 日
0.1.0 2020 年 4 月 12 日

#6#rustic

MIT/Apache

39KB
663 代码行

Rustic

Rustic 是一个围绕 Restic 备份程序的包装器。它支持在配置文件中添加备份配置文件,以将所有备份设置放在一个地方。

安装

使用 Cargo 进行安装

cargo install rustic-backup

用法

要备份配置文件 my_profile,运行

$ rustic backup my_profile

要使用其配置的保留策略忘记 my_profile 中的快照,运行

$ rustic forget my_profile

您可以将 --prune 标志添加到 rustic forget 以自动删除由忘记的快照引用的数据,或者单独运行 restic prune my_profile

要查看快照列表,运行

$ rustic snapshots my_profile

rustic snapshots 可以传递参数到 Restic 以筛选显示哪些快照

$ rustic snapshots my_profile -- --last

您还可以运行 rustic profiles 以打印出所有配置文件及其仓库位置的列表。

配置

为了使用 Rustic,您需要至少配置一个配置文件,告诉它要备份什么以及如何备份。Rustic 从 --config 标志或 RUSTIC_CONFIG 环境变量获取配置文件路径。

配置文件使用 TOML,并具有以下字段

# Path to the restic command. Defaults to `restic` if unspecified.
restic_command = "path/to/restic"

# Defines a profile named `my_profile`
[profiles.my_profile]
# Repository location. See https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html
# for examples and supported backends
repository = "local:my-test-repository"

# This is the directory to run backups from. Included and excluded files, as well as the `password_file` and
# `credentials_file` options, are interpreted relative to this. In most cases, it will be the root directory or your
# home directory.
base_directory = "/"

# If true, running `rustic backup` will create the repository if it doesn't already exist. Note that `rustic forget`, `rustic prune`, and
# `rustic snapshots` will not create the repository, as there isn't anything for them to do with a brand-new repository. Defaults to false.
auto_init = false

# Password for the Restic repository. Unless your Rustic configuration file is well-protected, it's recommended that you use `password_file` or
# `password_command` instead.
password = "not very secret"

# A text file containing the repository password. The path is interpreted relative to `base_directory`.
password_file = "my-password.txt"

# A shell command that prints out the repository password.
password_command = "password-helper restic"

# If true, ignore cache directories marked with a `CACHEDIR.TAG` file
# See http://bford.info/cachedir/spec.html
exclude_caches = false

# If true, do not cross filesystem boundaries when backing up
one_file_system = false

# If true, ignore inode number changes when checking for modified files
ignore_inode = false

# TOML file containing a map of environment variables to pass to Restic. This is merged with the `environment` table described below.
environment_file = "my-variables.txt"

# Optional map of environment variables to pass to Restic. This is generally for backend-specific credentials like AWS or Backblaze API keys,
# but can contain any variables.
[profiles.my_profile.environment]
B2_ACCOUNT_ID = "1234"
B2_ACCOUNT_KEY = "5678"

# The retention policy controls which snapshots to keep when running `rustic forget`. All fields are optional, but `rustic forget`
# will not do anything unless at least one is set.
[profiles.my_profile.retention]
# Keep the n most recent snapshots
keep_last = 5

# Keep the most recent n hourly snapshots (that is, for the past n hours that have snapshots, keep the most recent
# snapshot from that hour)
keep_hourly = 24

# Keep the most recent n daily snapshots
keep_daily = 7

# Keep the most recent n weekly snapshots
keep_weekly = 8

# Keep the most recent n monthly snapshots
keep_monthly = 12

# Keep the most recent n yearly snapshots
keep_yearly = 10

# Keep all snapshots within some duration of the most recent snapshot. The duration should be formatted as a
# number of years, months, days, and hours, like `1y3m10d2h` for the past 1 year, 3 months, 10 days, and 2 hours.
keep_within = "1y3m10d1h"

# Keep all snapshots with any of these combinations of tags. In this case, all snapshots with the `important` tag will be kept, and
# all snapshots with both `tag1` and `tag2`.
keep_tags = [
    ["important"],
    ["tag1", "tag2"]
]

# Fileset specifying which files to back up. See `filesets` below
[profiles.my_profile.include]
patterns = [
    "/etc",
    "/var",
    "/home/*/Documents"
]

# Fileset specifying which files to exclude from the backup
[profile.my_profile.exclude]
patterns = [
    "*.o",
    "/var/log"
]

inherits = ["base_excludes"]

# Filesets specify a set of files based on glob patterns. They can inherit the patterns from other filesets defined in the
# `filesets` table. Each backup profile has a fileset specifying which files to back up and (optionally) a fileset with patterns
# to exclude from the backup.
[filesets.base_excludes]
patterns = [
    "*.zip",
    "*.tar",
    "*.tar.gz"
]

依赖项

~9–21MB
~289K SLoC