Rclone - 同步不同云存储中的文件目录
Rclone是一个用Go语言编写的命令行程序,用于同步来自不同云存储提供商的文件和目录,例如:Amazon Drive、Amazon S3、Backblaze B2、Box、Ceph、DigitalOcean Spaces、Dropbox、 FTP、谷歌云存储、谷歌云端硬盘等。
如您所见,它支持多个平台,这使其成为在服务器之间同步数据或将数据同步到私人存储的有用工具。
Rclone 具有以下功能
- MD5/SHA1 哈希检查始终确保文件完整性。
- 时间戳保留在文件中。
- 支持整个文件的部分同步。
- 新文件或更改文件的复制模式。
- 使目录相同的一种同步方法。
- 检查模式——哈希相等性检查。
- 可以与网络同步,例如两个不同的云帐户。
- (加密)后端。
- (缓存)后端。
- (联盟)后端。
- 可选 FUSE 安装(rclone 安装)。
如何在 Linux 系统中安装 rclone
rclone的安装可以通过两种不同的方式完成。更简单的方法是通过发出以下命令来使用其安装脚本。
curl https://rclone.org/install.sh | sudo bash
该脚本的作用是检查运行它的操作系统类型并下载与该操作系统相关的存档。然后,它提取存档并将 rclone 二进制文件复制到 /usr/bin/rclone 并授予该文件的 755 权限。
最后,安装完成后,您应该看到以下行:
Rclone v1.44 has successfully installed.
Now run “rclone config” for setup, Check https://rclone.org/docs/ for more details.
安装 rclone 的第二种方法是发出以下命令。
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64
现在复制二进制文件并赋予其可执行权限。
cp rclone /usr/bin/
chown root:root /usr/bin/rclone
chmod 755 /usr/bin/rclone
安装rclone联机帮助页。
mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
mandb
如何在 Linux 系统中配置 rclone
接下来您需要做的是运行rclone config来创建您的配置文件。它将用于将来使用rclone时进行身份验证。要运行配置设置,请运行以下命令。
rclone config
您将看到以下提示:
2018/11/13 11:39:58 NOTICE: Config file “/home/user/.config/rclone/rclone.conf” not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q>
选项如下:
- n) – 创建新的远程连接
- s) – 为您的配置设置密码保护
- q) – 退出配置
出于本教程的目的,让我们按 "n"
并创建新连接。系统会要求您为新连接命名。之后,系统将提示您选择要配置的存储类型:
我已按连接命名“Google”,并选择了“Google Drive”,它位于数字12下方。其余问题您只需保留默认答案即可回答,即空的“ ”。
当系统要求时,您可以选择“自动配置”,这将生成连接到您的 Google 云端硬盘所需的所有信息,并授予rclone权限使用Google 云端硬盘中的数据。
该过程看起来像这样:
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
ID of the root folder - leave blank normally. Fill in to access "Computers" folders. (see docs).
root_folder_id>
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file>
Remote config
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine or Y didn't work
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 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":"2018-11-13T11:57:58.955387075Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
如何在 Linux 系统中使用 rclone
Rclone 有相当长的可用选项和命令列表。我们将尝试涵盖一些更重要的内容:
列出远程目录
rclone lsd <remote-dir-name>:
使用 rclone 复制数据
rclone copy source:sourcepath dest:destpath
请注意,如果 rclone 发现重复项,这些重复项将被忽略:
与 rclone 同步数据
如果你想在目录之间同步一些数据,你应该使用rclone和sync命令。
该命令应如下所示:
rclone sync source:path dest:path [flags]
在这种情况下,源会同步到目标,仅更改目标!此方法会跳过未更改的文件。由于该命令可能会导致数据丢失,因此您可以将其与“--dry-run”一起使用来查看到底将复制和删除哪些内容。
使用 rclone 移动数据
要移动数据,您可以将rclone与move命令结合使用。该命令应如下所示:
rclone move source:path dest:path [flags]
源中的内容将被移动(删除)并放置在选定的目标位置。
其他有用的 rclone 命令
在目标上创建目录。
rclone mkdir remote:path
删除目录。
rclone rmdir remote:path
检查源和目标上的文件是否匹配:
rclone check source:path dest:path
删除文件:
rclone delete remote:path
每个 rclone 命令都可以与不同的标志一起使用,并包含其自己的帮助菜单。例如,您可以使用删除选项进行选择性删除。假设您要删除大于100M的文件,命令如下所示。
rclone --min-size 100M delete remote:path
强烈建议您查看每个命令的手册和帮助,以充分利用 rclone。 rclone 的完整文档位于:https://rclone.org/
结论
rclone 是一个功能强大的命令行实用程序,可帮助您管理不同云存储提供商之间的数据。虽然在本文中我们只触及了 rclone 功能的表面,但它还有更多的功能可以实现,特别是与 cron 服务结合使用时(例如)。