restic 备份工具
-
Restic 是一款命令行下的数据备份工具,采用 Go 语言开发,采用 BSD 2-Clause License 协议开源,提供 Windows、Linux 和 Mac OS X 全平台支持。使用 Restic 可以很方便的把文件加密备份到 AWS S3、阿里云 OSS、Backblaze B2 等常见对象存储,当然,也可以将数据加密备份到本地。
-
手动安装 官方仓库下载最新版本程序 https://github.com/restic/restic/releases
由于 restic 只是一个独立的二进制文件,只要放到系统 $PATH 包含的路径并赋予执行权限即可。 具体请查看官方文档https://restic.readthedocs.io/en/stable/
-
添加命令自动补全
yum install bash-completion -y
restic generate --bash-completion /etc/bash_completion.d/restic
- 初始化存储库 ssh需要提前设定免密登录
请运行以下命令并输入相同的密码两次
restic -r sftp:192.168.0.31:/srv/restic-repo init
- 备份
运行以下命令,然后再次输入您在上方选择的存储库密码
restic -r sftp:192.168.0.31:/srv/restic-repo backup /opt/work
- 查看快照
restic -r sftp:192.168.0.31:/srv/restic-repo snapshots
- 还原
需要还原的快照id和还原位置
restic -r sftp:192.168.0.31:/srv/restic-repo restore id --target /tmp/h
- 配置环境变量
export RESTIC_REPOSITORY=sftp:192.168.0.31:/srv/restic-repo
export RESTIC_PASSWORD=123123