查看原文
其他

14k Star!一个快速、安全、高效的备份程序!

小秋 开源前哨 2022-09-24

简介

restic 是一个快速、高效、安全的备份程序。它支持三大操作系统(Linux、macOS、Windows)和一些较小的操作系统(FreeBSD、OpenBSD)。

项目地址:

https://github.com/restic/restic

安装

这里只介绍三大操作系统的安装方法,其他类型的操作系统请参考官网。

macOS

# 使用以下之一都可以
$ brew install restic
$ sudo port install restic

RHEL 和 CentOS

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

Windows

# 使用此安装方法,restic.exe 将自动添加到 PATH 环境变量中
scoop install restic

使用 docker 容器

$ docker pull restic/restic

备份

准备存储仓库

保存备份的位置称为“存储仓库”。仓库可以存储在本地,也可以存储在某个远程服务器或服务上。restic 接受环境变量 RESTIC_REPOSITORY 指定的仓库位置,也可以从通过 --repository-file 选项指定存储仓库的位置。

本地

在本地创建存储仓库 /srv/restic-repo,运行以下命令:

$ restic init --repo /srv/restic-repo
enter password for new repository:
enter password again:
created restic repository 085b3c76b9 at /srv/restic-repo
Please note that knowledge of your password is required to access the repository.
Losing your password means that your data is irrecoverably lost.

要注意的是,访问仓库的密码十分重要,一旦遗忘就无法访问备份在仓库中的数据。

备份,将 ~/work 目录中的文件备份到创建的本地仓库中:

$ restic -r /srv/restic-repo --verbose backup ~/work
open repository
enter password for repository:
password is correct
lock repository
load index files
start scan
start backup
scan finished in 1.837s
processed 1.720 GiB in 0:12
Files:        5307 new,     0 changed,     0 unmodified
Dirs:         1867 new,     0 changed,     0 unmodified
Added:      1.200 GiB
snapshot 40dc1520 saved

SFTP

使用 SFTP 备份数据,必须首先使用 SSH 设置服务器并让它知道公钥。无密码登录非常重要,因为如果服务器提示输入凭据,restic 将无法连接到存储库。

配置服务器后,可以通过更改 init 命令中的 URL 方案简单地实现 SFTP 存储库的设置:

$ restic -r sftp:user@host:/srv/restic-repo init
enter password for new repository:
enter password again:
created restic repository f1c6108821 at sftp:user@host:/srv/restic-repo
Please note that knowledge of your password is required to access the repository.
Losing your password means that your data is irrecoverably lost.

其他

除了本地备份和通过 SFTP 备份,restic 还支持其他后端服务备份:

  • HTTP REST 服务器
  • AWS S3(来自 Amazon 或使用Minio服务器)
  • OpenStack Swift
  • BackBlaze B2
  • Microsoft Azure Blob 存储
  • 谷歌云存储

恢复

恢复数据有两种方式,一是从快照恢复,二是使用 mount 恢复。

从快照恢复

使用以下命令,即可将备份数据恢复到 /tmp/restore-work:

$ restic -r /srv/restic-repo restore 79766175 --target /tmp/restore-work
enter password for repository:
restoring <Snapshot of [/home/user/work] at 2015-05-08 21:40:19.884408621 +0200 CEST> to /tmp/restore-work

使用 mount 恢复

将备份作为常规文件系统浏览也很容易。首先,创建一个挂载点 /mnt/restic,然后使用以下命令为存储仓库提供服务:

$ mkdir /mnt/restic
$ restic -r /srv/restic-repo mount /mnt/restic
enter password for repository:
Now serving /srv/restic-repo at /mnt/restic
When finished, quit with Ctrl-c or umount the mountpoint.

设计原则

Restic 是一个可以正确进行备份的程序,其设计遵循以下原则:

  • 简单:备份是一个很顺畅的过程,Restic 易于配置和使用,以便在数据丢失的情况下,可以直接恢复它。同样,恢复数据也不复杂。

  • 快速:使用 restic 备份数据仅受网络或硬盘带宽的限制,以便可以每天备份文件。如果需要太多时间,没有人会进行备份。恢复备份只传输要恢复的文件所需的数据,这个过程也很快。

  • 可验证:比备份更重要的是恢复,restic 可以轻松验证所有数据是否可以恢复。

  • 安全:Restic 使用加密技术来保证数据的机密性和完整性。

  • 高效:随着数据的增长,额外的快照应该只占用实际增量的存储。更重要的是,在将重复数据实际写入存储后端之前,应该对其进行去重,以节省宝贵的备份空间。

- EOF - 


更多优秀开源项目(点击下方图片可跳转)




开源前哨

日常分享热门、有趣和实用的开源项目。参与维护10万+star 的开源技术资源库,包括:Python, Java, C/C++, Go, JS, CSS, Node.js, PHP, .NET 等

关注后获取

回复 资源 获取 10万+ star 开源资源



分享点赞在看

支持我们分享更多优秀开源项目,谢谢!

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存