Linux 实用工具:Restic 跨平台备份工具

Restic 是一款 GO 语言开发的开源免费且快速、高效和安全的跨平台备份工具。Restic 使用加密技术来保证你的数据安全性和完整性,可以将本地数据加密后传输到指定的存储。

Restic 同样支持增量备份,可随时备份和恢复备份。Restic 支持大多数主流操作系统,比如:Linux、macOS、Windows 以及一些较小众的操作系统 FreeBSD 和 OpenBSD 等。

支持的存储库

  • 本地存储
  • SFTP 服务
  • REST Server
  • Amazon S3
  • Minio Server
  • OpenStack Swift
  • Backblaze B2
  • Microsoft Azure Blob Storage
  • Google Cloud Storage
  • 通过 Rclone 挂载的存储 (比如:Google Drive、OneDrive 等)

实践是检验真理的唯一标准,既然那么好,我们就测试看看。

安装包方式安装

Alpine Linux

在 Alpine Linux 上,你可以通过官方社区存储库安装软件包安装 restic,例如使用apk

apk add restic
Arch Linux

在 Arch Linux 上,有一个来自官方社区存储库,名为的 restic 安装的软件包 ,例如:pacman -S

pacman -S restic
Debian

在 Debian 上,有一个名为的包restic可以从官方存储库安装,例如apt-get:

apt-get install restic
Fedora

restic 可以使用以下方式安装dnf:

dnf install restic

如果你之前使用过 copr 的 restic,请按如下方式删除 copr repo 以避免任何冲突:

dnf copr remove copart/restic
macOS

如果你使用的是 macOS,则可以使用Homebrew安装 restic :

brew install restic

在 Linux 和 macOS 上,你也可以使用pkgx安装它:

pkgx install restic

您也可以使用MacPorts安装它:

sudo port install restic
Nix 和 NixOS

如果你正在使用Nix / NixOS, 那么有一个名为的软件包可用restic。可以使用以下命令安装它nix-env:

nix-env --install restic
OpenBSD

在 OpenBSD 6.3 及更高版本上,你可以使用以下命令安装 restic pkg_add:

pkg_add restic
FreeBSD

在 FreeBSD(11 以及可能的更高版本)上,你可以使用以下命令安装 restic :pkg install

pkg install restic
openSUSE

在 openSUSE(leap 15.0 及更高版本,以及 tumbleweed)上,你可以使用zypper包管理器安装 restic:

zypper install restic
RHEL 和 CentOS

对于 RHEL / CentOS Stream 8 & 9,可以从 EPEL 存储库安装 restic:

dnf install epel-release
dnf install restic

对于 RHEL7/CentOS,有一个可用的 copr 存储库,您可以尝试以下操作:

yum install yum-plugin-copr
yum copr enable copart/restic
yum install restic

如果这不起作用,您可以尝试直接添加存储库,对于 CentOS6 使用:

yum-config-manager –add-repo https://copr.fedorainfracloud.org/coprs/copart/restic/repo/epel-6/copart-restic-epel-6.repo

对于 CentOS7 使用:

yum-config-manager --add-repo https://copr.fedorainfracloud.org/coprs/copart/restic/repo/epel-7/copart-restic-epel-7.repo
Solus

可以通过包管理器从 Solus 的官方仓库安装 restic eopkg:

eopkg install restic
Windows

可以使用Scoop安装 restic :

scoop install restic

使用此安装方法,restic.exe 将自动加入 PATH。可以从 cmd.exePowerShell 键入 restic 来调用它。

下载安装

CentOS 安装 Restic

二进制文件安装

yum install -y bzip2
cd /usr/local/src && wget https://github.com/restic/restic/releases/download/v0.17.0/restic_0.17.0_linux_amd64.bz2
# 因国内环境情况,建议手动下载后,放置在目标目录:https://github.com/restic/restic/releases
cd /usr/local/src && bzip2 -k -d restic_0.17.0_linux_amd64.bz2
mv restic_0.17.0_linux_amd64 restic
chmod -R 755 restic
sudo mv restic /usr/local/bin/

源码安装

cd /usr/local/src && wget https://github.com/restic/restic/releases/download/v0.17.0/restic-0.17.0.tar.gz
cd /usr/local/src && tar -zxvf restic-0.17.0.tar.gz
cd restic-0.17.0
go run build.go
mv restic /usr/bin/restic

使用 restic -h 查看使用方法:

restic -h
restic is a backup program which allows saving multiple revisions of files and
directories in an encrypted repository stored on different backends.

The full documentation can be found at https://restic.readthedocs.io/ .

Usage:
  restic [command]

Available Commands:
  backup        Create a new backup of files and/or directories
  cache         Operate on local cache directories
  cat           Print internal objects to stdout
  check         Check the repository for errors
  copy          Copy snapshots from one repository to another
  diff          Show differences between two snapshots
  dump          Print a backed-up file to stdout
  find          Find a file, a directory or restic IDs
  forget        Remove snapshots from the repository
  generate      Generate manual pages and auto-completion files (bash, fish, zsh, powershell)
  help          Help about any command
  init          Initialize a new repository
  key           Manage keys (passwords)
  list          List objects in the repository
  ls            List files in a snapshot
  migrate       Apply migrations
  mount         Mount the repository
  prune         Remove unneeded data from the repository
  recover       Recover data from the repository not referenced by snapshots
  repair        Repair the repository
  restore       Extract the data from a snapshot
  rewrite       Rewrite snapshots to exclude unwanted files
  self-update   Update the restic binary
  snapshots     List all snapshots
  stats         Scan the repository and show basic statistics
  tag           Modify tags on snapshots
  unlock        Remove locks other processes created
  version       Print version information

Flags:
      --cacert file                file to load root certificates from (default: use system c                                                                                                  ertificates or $RESTIC_CACERT)
      --cache-dir directory        set the cache directory. (default: use system default cach                                                                                                  e directory)
      --cleanup-cache              auto remove old cache directories
      --compression mode           compression mode (only available for repository format ver                                                                                                  sion 2), one of (auto|off|max) (default: $RESTIC_COMPRESSION) (default auto)
  -h, --help                       help for restic
      --http-user-agent string     set a http user agent for outgoing http requests
      --insecure-no-password       use an empty password for the repository, must be passed t                                                                                                  o every restic command (insecure)
      --insecure-tls               skip TLS certificate verification when connecting to the r                                                                                                  epository (insecure)
      --json                       set output mode to JSON for commands that support it
      --key-hint key               key ID of key to try decrypting first (default: $RESTIC_KE                                                                                                  Y_HINT)
      --limit-download rate        limits downloads to a maximum rate in KiB/s. (default: unl                                                                                                  imited)
      --limit-upload rate          limits uploads to a maximum rate in KiB/s. (default: unlim                                                                                                  ited)
      --no-cache                   do not use a local cache
      --no-extra-verify            skip additional verification of data before upload (see do                                                                                                  cumentation)
      --no-lock                    do not lock the repository, this allows some operations on                                                                                                   read-only repositories
  -o, --option key=value           set extended option (key=value, can be specified multiple                                                                                                   times)
      --pack-size size             set target pack size in MiB, created pack files may be lar                                                                                                  ger (default: $RESTIC_PACK_SIZE)
      --password-command command   shell command to obtain the repository password from (defa                                                                                                  ult: $RESTIC_PASSWORD_COMMAND)
  -p, --password-file file         file to read the repository password from (default: $RESTI                                                                                                  C_PASSWORD_FILE)
  -q, --quiet                      do not output comprehensive progress report
  -r, --repo repository            repository to backup to or restore from (default: $RESTIC_                                                                                                  REPOSITORY)
      --repository-file file       file to read the repository location from (default: $RESTI                                                                                                  C_REPOSITORY_FILE)
      --retry-lock duration        retry to lock the repository if it is already locked, take                                                                                                  s a value like 5m or 2h (default: no retries)
      --tls-client-cert file       path to a file containing PEM encoded TLS client certifica                                                                                                  te and private key (default: $RESTIC_TLS_CLIENT_CERT)
  -v, --verbose                    be verbose (specify multiple times or a level using --verb                                                                                                  ose=n, max level/times is 2)

Use "restic [command] --help" for more information about a command.

Windows 安装 Restic

作者:Jeebiz  创建时间:2024-08-16 15:54
最后编辑:Jeebiz  更新时间:2024-11-01 12:20