Rclone安装并挂载GoogleDrive 作者: Hogwarts 发布于: 2021-12-30 更新于: 2023-11-29 分类: 默认分类 秋水逸冰的一键备份脚本backup.sh,垂涎已久,很久以前就想学习。这个脚本虽说是一键,但还需要修改一些自己的参数,比如说一些路径、密码啥的。没实际操作过,水平太低,看着就烦。 文章中还有配置 rclone 的命令,并且rclone还得必须安装和配置。看来得先从学习rclone开始了,里面有qcmoke大佬的链接`https://www.qcmoke.site/tools/rclone.html `,已经打不开了。就像破案一样,线索断了。功夫不负有心人,在github上找到了qcmoke的库,没有用呀,没有具体的内容。然后就在Google里面搜来搜去,终于搜到了一篇可能是爬来的文章,按照此文的讲解顺序,成功安装rclone,并且成功挂载GoogleDrive。 以挂载GoogleDrive为例,学习rclone的安装与配置。经测试,rclone成功挂载后,两端会同步操作。 #一、安装rclone前的准备工作 ##1.1 安装必要的软件 yum -y install fuse fuse3 不安装fuse,在挂载时会报错 Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH ##1.2 先创建一个目录作为云盘的挂载点 mkdir -p /data/GoogleDrive ##1.3 在GoogleDrive中创建一个保存目录 在云盘的根目录下创建Backup文件夹 #二、rclone安装和基本配置 ##2.1 rclone安装 ~~不要用此自动命令安装了,自动安装的是最新版本。截至2022年4月1日是v1.58.0。1.58.0已经不适用rclone config的基本配置了。建议手动下载v1.57.0版,然后运行rclone config基本配置的命令。~~ curl https://rclone.org/install.sh | sudo bash ~~roclone v1.57.0版Github下载页面 `https://github.com/rclone/rclone/releases` 根据自己的系统下载相应的版本即可。~~ **可参考新篇** https://winamp.top/219.html ##2.2 rclone config基本配置 root@debian:~# rclone config #输入rclone config命令进行配置 No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n #选择n创建新的远端 name> mydrive # 输入remote的名字,随意。本例输入的是mydrive。 Option Storage. Type of storage to configure. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value. 1 / 1Fichier \ "fichier" 2 / Alias for an existing remote \ "alias" 3 / Amazon Drive \ "amazon cloud drive" 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS \ "s3" 5 / Backblaze B2 \ "b2" 6 / Better checksums for other remotes \ "hasher" 7 / Box \ "box" 8 / Cache a remote \ "cache" 9 / Citrix Sharefile \ "sharefile" 10 / Compress a remote \ "compress" 11 / Dropbox \ "dropbox" 12 / Encrypt/Decrypt a remote \ "crypt" 13 / Enterprise File Fabric \ "filefabric" 14 / FTP Connection \ "ftp" 15 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 16 / Google Drive \ "drive" 17 / Google Photos \ "google photos" 18 / Hadoop distributed file system \ "hdfs" 19 / Hubic \ "hubic" 20 / In memory object storage system. \ "memory" 21 / Jottacloud \ "jottacloud" 22 / Koofr \ "koofr" 23 / Local Disk \ "local" 24 / Mail.ru Cloud \ "mailru" 25 / Mega \ "mega" 26 / Microsoft Azure Blob Storage \ "azureblob" 27 / Microsoft OneDrive \ "onedrive" 28 / OpenDrive \ "opendrive" 29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 30 / Pcloud \ "pcloud" 31 / Put.io \ "putio" 32 / QingCloud Object Storage \ "qingstor" 33 / SSH/SFTP Connection \ "sftp" 34 / Sia Decentralized Cloud \ "sia" 35 / Sugarsync \ "sugarsync" 36 / Tardigrade Decentralized Cloud Storage \ "tardigrade" 37 / Transparently chunk/split large files \ "chunker" 38 / Union merges the contents of several upstream fs \ "union" 39 / Uptobox \ "uptobox" 40 / Webdav \ "webdav" 41 / Yandex Disk \ "yandex" 42 / Zoho \ "zoho" 43 / http Connection \ "http" 44 / premiumize.me \ "premiumizeme" 45 / seafile \ "seafile" Storage> 16 #选择要挂载到vps上的第三方云盘,由于这里挂载的是谷歌云盘,故选择16。 Option client_id. Google Application Client Id Setting your own is recommended. See https://rclone.org/drive/#making-your-own-client-id for how to create your own. If you leave this blank, it will use an internal key which is low performance. Enter a string value. Press Enter for the default (""). client_id> #回车,此处为基本操作。先输入默认的即可,等熟练了再自定义。 Option client_secret. OAuth Client Secret. Leave blank normally. Enter a string value. Press Enter for the default (""). client_secret> #回车,意义同上。 Option scope. Scope that rclone should use when requesting access from drive. Enter a string value. Press Enter for the default (""). 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 #选择1,赋予rclone操作云盘可读可写的权限 Option root_folder_id. ID of the root folder. Leave blank normally. Fill in to access "Computers" folders (see docs), or for rclone to use a non root folder as its starting point. Enter a string value. Press Enter for the default (""). root_folder_id> #回车 Option service_account_file. Service Account Credentials JSON file path. Leave blank normally. Needed only if you want use SA instead of interactive login. Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`. Enter a string value. Press Enter for the default (""). service_account_file> #回车 Edit advanced config? y) Yes n) No (default) y/n> #回车,是否高级配置,默认即可。 Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine y) Yes (default) n) No y/n> n #是否使用自动配置,选n不配置 Option config_verification_code. Verification code Go to this URL, authenticate then paste the code here. https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=6PaR-Ys_ilfw-Nzbq5Aj2A Enter a string value. Press Enter for the default (""). config_verification_code> #复制一下获得的验证码到此处 #打开浏览器输入以上链接并以挂载的谷歌云盘对应的账号登陆验证码。 对话框显示:请复制以下代码,切换到您的应用,然后粘贴此代码: 4/1AX4XfWhmliVDR6L8W****** Configure this as a Shared Drive (Team Drive)? y) Yes n) No (default) y/n> #回车 -------------------- [mydrive] type = drive scope = drive token = {"access_token":"ya2bdh0vZ3zMsBo0qFZ6-IYPDpiYhio3dU1Tj_j8fSRMz15hSkbPNL-BfaH3cHGxcz_a-2wnZ","token_type":"Bearer","refresh_token":"1//0ehAAGA4SNwF-L9IrA8RH5TSF-gjtpMLqfkm43DJhcnmC4","expiry":"2021-12-29T20:29:55.689621751+08:00"} team_drive = -------------------- y) Yes this is OK (default) e) Edit this remote d) Delete this remote y/e/d> #回车 Current remotes: Name Type ==== ==== mydrive drive e) Edit existing remote n) New remote d) Delete remote r) Rename remote c) Copy remote s) Set configuration password q) Quit config e/n/d/r/c/s/q> q #输入q退出 root@debian:~#如果是安装秋大的一键备份脚本的话,到此处就可以了,不要进行下面的挂载操作。 ##2.3 学习rclone copy命令 看秋大的一键脚本用到的是rclone copy命令,经多次学习尝试,终于自行运行成功,但脚本不能成功备份。 rclone copy /opt/backups/debian_20220101205758.tgz.enc mydrive:Backup **命令说明如下** - rclone copy: 备份命令 - /opt/backups/debian_20220101205758.tgz.enc: 要备份的文件或目录 - mydrive: 配置rclone的名字(本例是mydrive) - Backup: GoogleDrive已经建立好的文件夹(本例是在GD上建立的Backup文件夹) 有可能出现运行不成功的问题,将client_id和client_secret换成自己的API接口,具体的看下一篇文章。[Rclone挂载GoogleDrive的API获取](https://winamp.top/161.html "Rclone挂载GoogleDrive的API获取") ##2.4 常用命令参数 命令 说明 rclone config 添加、删除、管理网盘等操作 rclone config file 显示配置文件的路径 rclone config show 显示配置文件信息 #三、挂载 ##3.1 挂载命令 rclone mount mydrive:Backup /data/GoogleDrive --allow-other --allow-non-empty --vfs-cache-mode writes & 执行挂载命令,其中 - **mydriver**是配置Rclone时设置的远端云盘名称; - **Backup**是谷歌云上的一个目录(必须先创建); - **/data/GoogleDrive**是vps上的挂载点,或者说是共享文件夹。 ##3.2 查看挂载与否 root@debian:~# df -h Filesystem Size Used Avail Use% Mounted on udev 481M 0 481M 0% /dev tmpfs 98M 11M 88M 11% /run /dev/vda1 24G 9.2G 14G 42% / tmpfs 490M 0 490M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 490M 0 490M 0% /sys/fs/cgroup tmpfs 98M 0 98M 0% /run/user/0 mydrive:Backup 15G 768M 15G 5% /data/GoogleDrive ##3.3 测试一下 echo "hello world" > /data/GoogleDrive/hello.txt ls /data/GoogleDrive/hello.txt 打开 Google Drive 刷新,看到hello.txt文件,说明初步成功了。 ##3.4 卸载磁盘 fusermount -qzu /data/GoogleDrive/ #此处必须是绝对路径 #四、加入开机启动 ##4.1 init.d模式(暂未测试) 下载并编辑自启脚本,P3TERX大佬编写好的 wget -N git.io/rcloned && nano rcloned 修改内容 NAME="Googledrive" #Rclone配置时填写的name REMOTE='' #远程文件夹,网盘里的挂载的一个文件夹,留空为整个网盘 LOCAL='/Googledrive' #挂载地址,VPS本地挂载目录 保存退出 设置开机自启 mv rcloned /etc/init.d/rcloned chmod +x /etc/init.d/rcloned # Debian/Ubuntu update-rc.d -f rcloned defaults # CentOS chkconfig rcloned on bash /etc/init.d/rcloned start 看到 [信息] rclone 启动成功 ! 即可。 其他管理命令 开始挂载 bash /etc/init.d/rcloned start 停止挂载 bash /etc/init.d/rcloned stop 重新挂载 bash /etc/init.d/rcloned restart 查看日志 tail -f /$HOME/.rclone/rcloned.log #注意路径,$HOME有可能是root。 ##4.2 systemctl模式 vim /etc/systemd/system/rclone.service [Unit] Description=rclone mount %I drive After=network.target [Service] Type=simple ExecStart=/usr/bin/rclone mount mydrive:Backup /data/GoogleDrive --allow-other --allow-non-empty --vfs-cache-mode writes #上面的挂载命令,文件夹的名称可能需要修改 [Install] WantedBy=multi-user.target systemctl daemon-reload systemctl start rclone systemctl status rclone systemctl enable rclone #挂载多个的话,可以再加一个service。 #五、参考 1. [通过Rclone挂载Google Drive到VPS](https://www.dazhuanlan.com/sk23/topics/1191766 "通过Rclone挂载Google Drive到VPS") 1. [配置Rclone将Google Drive挂载到VPS](https://seaug.com/?p=435 "配置Rclone将Google Drive挂载到VPS") 1. [在Debian/Ubuntu上使用rclone挂载Google Drive网盘](https://www.moerats.com/archives/481/ "在Debian/Ubuntu上使用rclone挂载Google Drive网盘") 标签: rclone, googledrive