Rclone  - 从不同的云存储同步文件目录

Rclone是一个用Go语言编写的命令行程序,用于同步来自不同云存储提供商的文件和目录,例如:Amazon Drive,Amazon S3,Backblaze B2,Box,Ceph,DigitalOcean Spaces,Dropbox,FTP,Google Cloud Storage,Google驾驶等

如您所见,它支持多个平台,这使其成为在服务器或私有存储之间同步数据的有用工具。

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配置来创建配置文件。 它将用于身份验证以供将来使用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"并创建新连接。 系统将要求您为新连接命名。 之后,系统将提示您选择要配置的存储类型:

rclone - 新的远程连接

我已通过连接“Google”命名,并选择了“Google Drive” ,其数量为12 您可以通过简单地保留默认答案来回答其余问题,这是一个空的“”

当被要求时,您可以选择“autoconfig” ,这将生成连接到您的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复制数据

# rclone copy source:sourcepath dest:destpath

请注意,如果rclone发现重复项,则会忽略这些重复项:

rclone - 复制数据

使用rclone同步数据

如果要在目录之间同步某些数据,则应使用带有sync命令的rclone

该命令应如下所示:

# rclone sync source:path dest:path [flags]

在这种情况下,源将同步到目标,仅更改目标! 此方法会跳过未更改的文件。 由于该命令可能导致数据丢失,因此您可以将其与“-dry-run”一起使用,以查看将要复制和删除的内容。

rclone同步数据

使用rclone移动数据

要移动数据,可以使用rclone with 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命令都可以与不同的标志一起使用,并包含自己的帮助菜单。 例如,您可以使用delete选项进行选择性删除。 假设您要删除大于100M的文件,命令将如下所示。

# rclone --min-size 100M delete remote:path

强烈建议您查看手册并获取每个命令的帮助以充分利用rclone 有关rclone的完整文档,请访问: https ://rclone.org/

结论

rclone是一个功能强大的命令行实用程序,可帮助您管理不同云存储提供程序之间的数据。 虽然在本文中我们只讨论了rclone功能的表面,但还有很多功能可以实现,特别是与cron服务结合使用时(例如)。

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏