Rest Server
Rest Server 是一个高性能的 HTTP 服务器,它实现了 restic 的 REST 后端 API。它提供了安全有效的方法来远程备份数据,使用 restic 备份客户端通过 rest: URL 进行备份。
要求
Rest Server需要Go 1.7或更高版本才能构建。 唯一经过测试的编译器是Go官方编译器。 使用gccgo构建服务器可能有效,但不受支持。
与Rest Server一起使用的restic备份客户端所需的版本是v0.7.1或更高版本。
安装
从源代码
构建
make
或
go run build.go
如果一切顺利,您将在当前目录中找到二进制文件。
或者,您可以使用标准的 go install ./cmd/rest-server
在 $GOBIN 中编译和安装它。 但是,请注意,在编译时,您不会将版本信息内置到二进制文件中!
安装
make install
将二进制文件安装为 /usr/local/bin/rest-server
。
或者,您可以在您想要的任何地方手动安装它。它是一个单一的二进制文件,没有依赖关系。
Docker
构建映像
make docker_build
拉取映像
docker pull restic/rest-server
用法
要了解如何使用 restic 备份客户端与 REST 后端,请参阅 restic 手册.
rest-server --help Run a REST server for use with restic Usage: rest-server [flags] Flags: --append-only enable append only mode --cpu-profile string write CPU profile to file --debug output debug messages -h, --help help for rest-server --listen string listen address (default ":8000") --log string log HTTP requests in the combined log format --no-auth disable .htpasswd authentication --path string data directory (default "/tmp/restic") --private-repos users can only access their private repo --prometheus enable Prometheus metrics --tls turn on TLS support --tls-cert string TLS certificate path --tls-key string TLS key path -V, --version show version and quit
默认情况下,服务器将备份数据保存在 /tmp/restic
中。以禁用身份验证的自定义持久性目录启动服务器:
rest-server --path /user/home/backup --no-auth
To authenticate users (for access to the rest-server), the server supports using a .htpasswd
file to specify users. You can create such a file at the root of the persistence directory by executing the following command (note that you need the htpasswd
program from Apache's http-tools). In order to append new user to the file, just omit the -c
argument. Only bcrypt and SHA encryption methods are supported, so use -B (very secure) or -s (insecure by today's standards) when adding/changing passwords.
要对用户进行身份验证(用于访问 rest-server),服务器支持使用 .htpasswd 文件指定用户。您可以通过执行以下命令在持久性目录的根目录下创建这样一个文件(注意,您需要 Apache http-tools 中的 htpasswd 程序)。为了向文件添加新用户,只需省略 -c 参数。只支持 bcrypt 和 SHA 加密方法,所以在添加更改密码时使用 -B(非常安全)或 -s(以今天的标准来看不安全)。
htpasswd -B -c .htpasswd username
If you want to disable authentication, you must add the --no-auth
flag. If this flag is not specified and the .htpasswd
cannot be opened, rest-server will refuse to start.
NOTE: In older versions of rest-server (up to 0.9.7), this flag does not exist and the server disables authentication if .htpasswd
is missing or cannot be opened.
By default the server uses HTTP protocol. This is not very secure since with Basic Authentication, username and passwords will travel in cleartext in every request. In order to enable TLS support just add the --tls
argument and add a private and public key at the root of your persistence directory. You may also specify private and public keys by --tls-cert
and --tls-key
.
Signed certificate is required by the restic backend, but if you just want to test the feature you can generate unsigned keys with the following commands:
如果要禁用身份验证,则必须添加 --no-auth 标志。 如果未指定此标志且无法打开 .htpasswd,则 rest-server 将拒绝启动。
注意:在旧版本的 rest-server(最高0.9.7)中,此标志不存在,如果 .htpasswd 丢失或无法打开,服务器将禁用身份验证。
默认情况下,服务器使用 HTTP 协议。 这不是很安全,因为使用基本身份验证,用户名和密码将在每个请求中以明文形式传输。 为了启用 TLS 支持,只需添加 --tls 参数,并在持久性目录的根目录中添加私钥和公钥。 您还可以通过 --tls-cert 和 --tls-key 指定私钥和公钥。
restic 后端需要签名证书,但如果您只想测试该功能,可以使用以下命令生成未签名密钥:
openssl genrsa -out private_key 2048 openssl req -new -x509 -key private_key -out public_key -days 365
--append-only 模式允许创建新备份,但可以防止删除和修改现有备份。备份可能被黑客入侵的系统时,此功能非常有用。
为了防止用户访问彼此的存储库,您可以使用 --private-repos
标志,该标志仅在存储库 URL 中指定了与用户同名的子目录时才授予访问权限。例如,用户 "foo" 使用存储库URL rest:https://foo:pass@host:8000/foo
, rest:https://foo:pass@host:8000/foo/
或 rest:https://foo:pass@host:8000/foo/bar
将被授予访问权限,但使用存储库URL的同一用户 rest:https://foo:pass@host:8000/
或 rest:https://foo:pass@host:8000/foobar/
将被拒绝访问。
Rest Server 使用与本地后端完全相同的目录结构,因此您应该能够在本地和通过 HTTP 访问它,甚至可以同时访问它。
Systemd
源代码中包含一个示例 systemd service file,因此您可以立即启动并运行 Rest Server 作为正确的 Systemd 服务。在安装之前,请根据您的环境调整路径和选项。
Docker
默认情况下,映像使用身份验证。要关闭它,请将环境变量 DISABLE_AUTHENTICATION
设置为任意值。
持久数据卷位于 /data
。
启动服务器
docker run -p 8000:8000 -v /my/data:/data --name rest_server restic/rest-server
建议设置容器名称,以便更容易地管理用户(参见下一节)。
您可以将环境变量 OPTIONS
设置为希望传递给 rest-server 的任何额外标志。
管理用户
添加用户
docker exec -it rest_server create_user myuser
或
docker exec -it rest_server create_user myuser mypassword
删除用户
docker exec -it rest_server delete_user myuser
Prometheus 支持和 Grafana 仪表板
服务器可以从 --prometheus 启动,以在 /metrics 上公开 Prometheus 度量。
此存储库包含示例完整堆栈Docker Compose设置,其中包含示例 examples/compose-with-grafana/ 的 Grafana 仪表板。
为何使用 Rest Server?
与 SFTP 后端相比,REST 后端具有更好的性能,尤其是如果您可以通过使用普通HTTP传输来跳过额外的加密开销(restic已经正确加密了它发送的所有数据,因此使用 HTTPS主 要是关于身份验证)。
但是,即使你使用 HTTPS 传输,由于 SFTP 协议的一些低效率,REST 协议应该更快,更具可扩展性(所有内容都需要以 32 KiB的块为单位传输,每个数据包都需要服务器确认)。
最后,Rest Server实现非常简单,因此可以在低端设备上使用,没问题。此外,在某些情况下,例如在企业防火墙后面,HTTP / S可能是唯一允许的协议。 REST后端也可能是满足您备份需求的最佳选择。
贡献者
欢迎贡献者,只要打开一个新的问题或拉请求。
许可
The BSD 2-Clause License Copyright © 2015, Bertil Chapuis Copyright © 2016, Zlatko Čalušić, Alexander Neumann Copyright © 2017, The Rest Server Authors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(First edition: vz edited at 2019.09.18)