[Docker] Kopia 通过 Rclone 实现对 Google Drive 的支持
Kopia 加密备份(在 Kopia 中称为 snapshots
)保存到各种存储位置,在 Kopia 中,存储位置称为 repository
。
- Kopia 原生支持 Google Drive,并通过 Kopia 的 Rclone 选项(见下文)。
- Kopia 对 Google Drive 的原生支持目前处于实验阶段。
- 原生 Google Drive 支持的运作方式与 Kopia 通过 Rclone 对 Google Drive 的支持不同。
本文介绍如何通过 Rclone 实现对 Google Drive 的支持。
Rclone
Rclone 是一个(免费且开源)第三方程序,Kopia 的 Docker 镜像中包含了 Rclone,但我们还是下载一份用来生成配置文件。
cd && mkdir rclone
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64
./rclone config
下面是如何创建一个名为“remote”的示例。第一次运行:
No remotes found, make a new one?
n) New remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
n/r/c/s/q> n
name> remote
Type of storage to configure.
Choose a number from below, or type in your own value
[snip]
XX / Google Drive
\ "drive"
[snip]
Storage> drive
Google Application Client Id - leave blank normally.
client_id>
Google Application Client Secret - leave blank normally.
client_secret>
Scope that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value
1 / Full access all files, excluding Application Data Folder.
\ "drive"
2 / Read-only access to file metadata and file contents.
\ "drive.readonly"
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ "drive.file"
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
\ "drive.appfolder"
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
\ "drive.metadata.readonly"
scope> 1
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file>
Remote config
Use web browser to automatically authenticate rclone with remote?
* Say Y if the machine running rclone has a web browser you can use
* Say N if running rclone on a (remote) machine without web browser access
If not sure try Y. If Y failed, try N.
y) Yes
n) No
y/n> y
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
Log in and authorize rclone for access
Waiting for code...
Got code
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No
y/n> n
--------------------
[remote]
client_id =
client_secret =
scope = drive
root_folder_id =
service_account_file =
token = {"access_token":"XXX","token_type":"Bearer","refresh_token":"XXX","expiry":"2014-03-16T13:57:58.955387075Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
初始设置涉及从 Google 驱动器获取令牌,我们需要在浏览器中执行此操作,这里我们可以通过 caddy
反代来打开 http://127.0.0.1:53682/auth
。
进入目录 /etc/caddy/sites
,创建并编辑 kopia.amaranthinking.eu.org.conf
,
kopia.amaranthinking.eu.org {
reverse_proxy 127.0.0.1:53682
}
重启 caddy,
systemctl restart caddy
访问 kopia.amaranthinking.eu.org/auth
即可,生成完毕后记得删除临时的反代配置。
注意:生成的 rclone 配置文件位于
/root/.config/rclone/rclone.conf
。
Kopia
接下来,将配置文件移动动 kopia
文件夹,
mv /root/.config/rclone/rclone.config /root/data/docker/kopia/rclone.conf
编辑 docker-compose.yml
文件,文件尾添加:
# Mount rclone config file
- ./rclone.conf:/app/rclone/rclone.conf
重启,
cd /root/data/docker/kopia/
docker-compose down
docker-compose up -d
设置 Rclone 后,Kopia 会自动管理和运行 Rclone,我们无需进行初始设置之外的太多操作。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭