rest-server

Rest Server 是一个高性能的 HTTP 服务器,它实现了 restic 的 Rest 后端。(Rest Server is a high performance HTTP server that implements restic's REST backend API.)

  • 所有者: restic/rest-server
  • 平台: BSD, Linux, Mac, Solaris, Windows, Plan 9, Docker
  • 許可證: BSD 2-Clause "Simplified" License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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)

概覽

名稱與所有者restic/rest-server
主編程語言Go
編程語言Go (語言數: 3)
平台BSD, Linux, Mac, Solaris, Windows, Plan 9, Docker
許可證BSD 2-Clause "Simplified" License
發布數11
最新版本名稱v0.12.1 (發布於 2023-07-09 17:17:22)
第一版名稱v0.9.2 (發布於 2017-06-02 09:51:45)
創建於2016-11-05 16:12:22
推送於2024-03-27 17:59:34
最后一次提交2024-03-27 18:59:33
星數832
關注者數29
派生數138
提交數529
已啟用問題?
問題數123
打開的問題數29
拉請求數121
打開的拉請求數11
關閉的拉請求數22
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

Rest Server

Build Status
Go Report Card
GoDoc
License
Powered by

Rest Server is a high performance HTTP server that implements restic's REST backend API. It provides secure and efficient way to backup data remotely, using restic backup client via the rest: URL.

Requirements

Rest Server requires Go 1.7 or higher to build. The only tested compiler is the official Go compiler. Building server with gccgo may work, but is not supported.

The required version of restic backup client to use with Rest Server is v0.7.1 or higher.

Installation

From source

Build

make

or

go run build.go

If all goes well, you'll find the binary in the current directory.

Alternatively, you can compile and install it in your $GOBIN with a standard go install ./cmd/rest-server. But, beware, you won't have version info built into binary when compiled that way!

Install

make install

Installs the binary as /usr/local/bin/rest-server.

Alternatively, you can install it manually anywhere you want. It's a single binary, there are no dependencies.

Docker

Build image

make docker_build

Pull image

docker pull restic/rest-server

Usage

To learn how to use restic backup client with REST backend, please consult restic manual.

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

By default the server persists backup data in /tmp/restic. To start the server with a custom persistence directory and with authentication disabled:

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.

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:

openssl genrsa -out private_key 2048
openssl req -new -x509 -key private_key -out public_key -days 365

The --append-only mode allows creation of new backups but prevents deletion and modification of existing backups. This can be useful when backing up systems that have a potential of being hacked.

To prevent your users from accessing each others' repositories, you may use the --private-repos flag which grants access only when a subdirectory with the same name as the user is specified in the repository URL. For example, user "foo" using the repository URLs rest:https://foo:pass@host:8000/foo, rest:https://foo:pass@host:8000/foo/ or rest:https://foo:pass@host:8000/foo/bar would be granted access, but the same user using repository URLs rest:https://foo:pass@host:8000/ or rest:https://foo:pass@host:8000/foobar/ would be denied access.

Rest Server uses exactly the same directory structure as local backend, so you should be able to access it both locally and via HTTP, even simultaneously.

Systemd

There's an example systemd service file included with the source, so you can get Rest Server up & running as a proper Systemd service in no time. Before installing, adapt paths and options to your environment.

Docker

By default, image uses authentication. To turn it off, set environment variable DISABLE_AUTHENTICATION to any value.

Persistent data volume is located to /data.

Start server

docker run -p 8000:8000 -v /my/data:/data --name rest_server restic/rest-server

It's suggested to set a container name to more easily manage users (see next section).

You can set environment variable OPTIONS to any extra flags you'd like to pass to rest-server.

Manage users

Add user
docker exec -it rest_server create_user myuser

or

docker exec -it rest_server create_user myuser mypassword
Delete user
docker exec -it rest_server delete_user myuser

Prometheus support and Grafana dashboard

The server can be started with --prometheus to expose Prometheus metrics at /metrics.

This repository contains an example full stack Docker Compose setup with a Grafana dashboard in examples/compose-with-grafana/.

Why use Rest Server?

Compared to the SFTP backend, the REST backend has better performance, especially so if you can skip additional crypto overhead by using plain HTTP transport (restic already properly encrypts all data it sends, so using HTTPS is mostly about authentication).

But, even if you use HTTPS transport, the REST protocol should be faster and more scalable, due to some inefficiencies of the SFTP protocol (everything needs to be transferred in chunks of 32 KiB at most, each packet needs to be acknowledged by the server).

Finally, the Rest Server implementation is really simple and as such could be used on the low-end devices, no problem. Also, in some cases, for example behind corporate firewalls, HTTP/S might be the only protocol allowed. Here too REST backend might be the perfect option for your backup needs.

Contributors

Contributors are welcome, just open a new issue / pull request.

License

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.
去到頂部