文件管理工具rclone基础用法

您所在的位置:网站首页 天翼云盘文件打开失败 文件管理工具rclone基础用法

文件管理工具rclone基础用法

2024-03-08 08:29| 来源: 网络整理| 查看: 265

简介

Rclone是一个命令行程序,用于管理云存储上的文件。它是云供应商的网络存储接口的一个功能丰富的替代方案。超过40种云存储产品支持rclone,包括S3对象存储、Ctyun ZOS。

 

Rclone具有与unix命令rsync、cp、mv、mount、ls、ncdu、tree、rm和cat相当的强大云功能。Rclone的语法与shell相似并且支持--dry-run 保护功能。rclone可以通过命令行、脚本或者对应的API使用。

 

下载与安装

rclone的官方下载链接是: https://rclone.org/downloads/

rclone的github:https://github.com/rclone/rclone

首先可以通过官方网站的下载页面,选择对应系统的支持版本,目前rclone支持覆盖绝大部分常见的系统。

通常是以zip包的形式提供(rclone-v1.62.2-windows-amd64.zip),部分系统也可以通过安装包安装方便管理(rclone-v1.62.2-linux-amd64.rpm)。

解压之后通过cmd或者是powershell打开对应的路径,执行./rclone.exe即可看到对应的usage输出。

配置

在开始使用对应的功能之前,需要先对远端信息进行配置,配置的方式总共有两种,一种是通过命令rclone config进行交互式配置,另一种是通过直接修改最后的原始配置文件进行配置;

在cmd中键入rclone config命令后,会出现一个文字交互流程,根据对应的提示进行操作即可完成配置:

首次使用的话,先输入n选择创建一个新的远端,然后输入remote的名称,然后选择对应的远端的类型,这里选择以一个s3类型的远端为例进行说明。

 

然后选择s3对应的运营商或者是服务的版本,这里我们选择社区原生的Ceph版本进行测试;

接着选择直接输入AK、SK,根据提示输入AK、SK与对应的服务地址(endpoint),然后后续在无特殊需求的情况下,可以一路回车,最后确认下完整的配置信息即可完成配置。

配置完成后交互界面会显示已经完成的配置信息:

另外一种方式是直接在对应的用户目录下创建一个叫做rclone.conf的文件,按照对应的格式输入参数,即可直接使用:

在windows环境下对应的文件路径是:C:/Users/Administrator/AppData/Roaming/rclone/rclone.conf

在linux环境下对应的文件路径是:/root/.config/rclone/rclone.conf

建议使用root用户,因为部分参数涉及创建文件夹删除文件等操作,如果用户权限较低的话可能会存在预期操作无法实现的情况。

 

基本语法

Rclone将一个目录树从一个存储系统同步到另一个。

它的语法是这样的

语法:[选项] 子命令

源路径和目标路径由您在配置文件中为存储系统指定的名称指定,然后是子路径,例如“drive:myfolder”,以查看远程存储系统“drive”中的文件夹“myfolder”。

您可以在配置文件中定义任意数量的存储路径。

请在学习rclone时使用--interactive/-i标志,以避免意外的数据丢失。

子命令

 

查看一个远端目录:

        rclone ls remote:path

拷贝一个本地目录到远端的目录:

        rclone copy /local/path remote:path

将本地目录同步到远端的目录:

        rclone sync --interactive /local/path remote:path

 

rclone最常用的命令如下,完整的命令列表可以通过help或者是rclone提供的文档查看:

        rclone config - Enter an interactive configuration session.        rclone copy - Copy files from source to dest, skipping already copied.        rclone sync - Make source and dest identical, modifying destination only.        rclone bisync - Bidirectional synchronization between two paths.        rclone move - Move files from source to dest.        rclone delete - Remove the contents of path.        rclone purge - Remove the path and all of its contents.        rclone mkdir - Make the path if it doesn't already exist.        rclone rmdir - Remove the path.        rclone rmdirs - Remove any empty directories under the path.        rclone check - Check if the files in the source and destination match.        rclone ls - List all the objects in the path with size and path.        rclone lsd - List all directories/containers/buckets in the path.        rclone lsl - List all the objects in the path with size, modification time and path.        rclone md5sum - Produce an md5sum file for all the objects in the path.        rclone sha1sum - Produce a sha1sum file for all the objects in the path.        rclone size - Return the total size and number of objects in remote:path.        rclone version - Show the version number.        rclone cleanup - Clean up the remote if possible.        rclone dedupe - Interactively find duplicate files and delete/rename them.        rclone authorize - Remote authorization.        rclone cat - Concatenate any files and send them to stdout.        rclone copyto - Copy files from source to dest, skipping already copied.        rclone genautocomplete - Output shell completion scripts for rclone.        rclone gendocs - Output markdown docs for rclone to the directory supplied.        rclone listremotes - List all the remotes in the config file.        rclone mount - Mount the remote as a mountpoint.        rclone moveto - Move file or directory from source to dest.        rclone obscure - Obscure password for use in the rclone.conf        rclone cryptcheck - Check the integrity of an encrypted remote.        rclone about - Get quota information from the remote.

 

常见的应用场景 从一个集群服务迁移到另一个集群服务

    从一个集群将对应的文件迁移到另一个集群的应用是比较常见的一种应用情况,下面以对象服务的迁移为例进行简单的介绍:

首先我们需要对两个服务都进行配置,第一个集群是test1,第二个集群是test2,现在需要将test1集群中的桶bucket1迁移到test2中。

可以使用如下的命令:

                    rclone copy test://bucket1 test2://bucket1

    如果在test2集群上没有这个桶bucket1的话,我们可以选择先手动在test2上创建对应的桶bucket1,也可以选择添加参数 --create-empty-src-dirs来自动创建:

                    rclone --create-empty-src-dirs copy test1://bucket1 test2://bucket2

    如果想要实时监控进度的话,可以使用参数—progress;

本地文件迁移到云上服务

    本地存在文件需要上云的情况下,也可以使用rclone来完成这个任务:

            rclone copy $localpath $remote://$bucket/$prefix

    可以用这个参数结构执行命令来完成任务,也可以根据实际情况添加相应的参数。

本地文件同步到云上服务

    本地文件在拷贝过一次后,或者是首次直接迁移到云端,也可以使用sync命令来完成:

            rclone sync $src_path  $dest_path

            eg: rclone sync /mnt/test test://bucket1/test

    sync与copy最大的区别在于sync命令是以“同步”为目的,也就是说,如果存在一个文件,dest端有而src端没有的话,会将dest端的文件清理掉。

注意事项 拷贝单个文件

    rclone通常会同步或复制目录。但是,如果源端指向一个文件,rclone将只复制该文件。目标远端必须指向一个目录rclone将给出错误Failed to create file system for“remote:file”:is a file not a directory if it not。

 

例如:存在一个文件叫test.png 想要复制的话,可以使用下面的命令:

                        rclone copy test.png remote://tmp/test.png

    但是不能使用 rclone copy test.png remote://test.png

    使用这个命令并不会直接创建一个对象remote://test.png 而是会创建一个这样的对象remote://test.png/test.png,并且会创建一个叫做test.png的桶而不是一个目录对象或者是prefix。

搭配其他网关服务使用

    rclone迁移或者的同步目录的时候,是不会复制目录对象的,例如:

    本地存在一个目录a,下面有目录b和d,目录b下有文件c,目录d是一个空目录,如果执行rclone copy a remote://tmp/a的话,预期可能会认为创建多个对象分别是

            tmp/a/

            tmp/a/b/

            tmp/a/b/c

            tmp/a/d/

    但是实际情况是只会创建一个/tmp/a/b/c的对象,因此在搭配类似于s3fs这类网关类型工具使用时,可能需要考虑对应的实际参数或者是用其他的方式补充完对应的目录对象,否则可能无法完成预期的需求。

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3