Total Pageviews

Friday 29 December 2017

使用 rclone 将文件同步至 Google Drive

下面开始讲 rclone 安装和同步方法, 首先 Google Dirve 账户一个, rclone 文件一份, linux 机器一个 (以 centos7 为例), 然后开始安装 rclone, 安装很简单, 复制粘贴加权限等.
首先是下载文件
yum install unzip wget -y
wget -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
安装帮助页 (此步骤可以省略, 但省略之后没有一些提示, 不推荐省略)
mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
mandb 
然后我们新建一个配置
rclone config
下面是直接在官网 copy 的添加 Google Dirve 的过程
    n) New remote
    d) Delete remote
    q) Quit config
    e/n/d/q> n
    name> shira(你的配置名称,此处随意填写但之后需要用到)
    Type of storage to configure.
    Choose a number from below, or type in your own value
     1 / Amazon Drive
       \ "amazon cloud drive"
     2 / Amazon S3 (also Dreamhost, Ceph, Minio)
       \ "s3"
     3 / Backblaze B2
       \ "b2"
     4 / Dropbox
       \ "dropbox"
     5 / Encrypt/Decrypt a remote
       \ "crypt"
     6 / Google Cloud Storage (this is not Google Drive)
       \ "google cloud storage"
     7 / Google Drive
       \ "drive"
     8 / Hubic
       \ "hubic"
     9 / Local Disk
       \ "local"
    10 / Microsoft OneDrive
       \ "onedrive"
    11 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
       \ "swift"
    12 / SSH/SFTP Connection
       \ "sftp"
    13 / Yandex Disk
       \ "yandex"
    Storage> 7(根据网盘类型选择Google Dirve)
    Google Application Client Id - leave blank normally.
    client_id>此处留空
    Google Application Client Secret - leave blank normally.
    client_secret>此处留空
    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> n(此处一定要选择n)
    If your browser doesn't open automatically go to the following
    link: https://accounts.google.com/o/oauth2/auth?xxxxxxxxxxxxxxxxx
Log in and authorize rclone for access
Enter verification code>xxxxxxxxxxx(将上面给出的url复制到你的浏览器打开,登录你的Google Dirve所在的google账户,然后将得到的一串字符串粘贴到此处)
    --------------------
    [shira]
    client_id =
    client_secret =
    token = {"AccessToken":"xxxx.x.xxxxx_xxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","RefreshToken":"1/xxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxx","Expiry":"2014-03-16T13:57:58.955387075Z","Extra":null}
    --------------------
    y) Yes this is OK
    e) Edit this remote
    d) Delete this remote
    y/e/d> y(确定信息并保存)
网上大多数 "教程" 到这里就没有了, 下面是在官网找到的一些操作和同步方法
列出文件和目录
rclone lsd shira: #列出配置名为shira的网盘的目录(不会显示文件)
rclone ls shira:anime #列出配置名为shira的网盘里anime目录下的文件(会显示包括子目录内的所有文件不显示目录)
文件和目录的复制剪切删除操作
rclone copy /root/anime shira:anime #复制本地/root/anime到配置名为shira的网盘的anime目录,反过来也可以
rclone move /root/anime shira:anime #剪切操作
rclone delete shira:anime #删除配置名为shira的网盘的anime目录
rclone mkdir shira:anime #创建配置名为shira的网盘的anime目录
同步文件
rclone sync /root/anime shira:anime#同步本地/root/anime到配置名为shira的网盘的anime目录,反过来也可以 
rclone sync shira2:donga shira:anime #同步本地配置名为shira2的网盘的donga目录到配置名为shira的网盘的anime目录,反过来也可以
官方下载页面:https://rclone.org/downloads/
其实用到的操作官网几乎都有, 其它需要可以在官网看.
-----

安装rclone

Rclone is a command line program developed to sync files and directories to and from various cloud storage services, like Google DriveAmazon S3DropboxMicrosoft OneDrive and Yandex Disk.
Rclone’s main features are:
  • MD5/SHA1 hashes are checked consistently for file integrity
  • Timestamps are preserved on files
  • Sync to and from the network, e.g: two different cloud accounts
  • Encryption
It is written in Go, and distributed under the MIT licence.
In this tutorial, we will install, configure and test rclone on Debian 8.

Installation

‘Go’ installation

First, you will need to install Go. It is available in the repository, you just need to execute the command:
# apt install golang
Make sure that you check if the $GOPATH is set:
$ echo $GOPATH
If not, set it just like this:
$ export GOPATH="$HOME/gopath/"
Now that you have installed Go, it’s possible to download rclone by executing the following command:
$ go get -u -v github.com/ncw/rclone
This will download and build the binary in $GOPATH/bin.
As the root, copy the binary to /usr/local/bin (or /usr/bin):
$ cd $GOPATH/bin
# cp rclone /usr/local/bin

Rclone configuration

Execute the following command:
$ rclone config
This will start the configuration process. After that, the program will print the following output:
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q>
Of course, when running the system for the first time, you’ll want to set a new remote, so type ‘n’ and then ENTER.
For the purpose of this tutorial, we will configure access to Dropbox, so, set “dropbox” as the new name
N.B.: you can choose any name you want, of course.
Rclone will print the following text:
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Dropbox
   \ "dropbox"
 5 / Encrypt/Decrypt a remote
   \ "crypt"
 6 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
 7 / Google Drive
   \ "drive"
 8 / Hubic
   \ "hubic"
 9 / Local Disk
   \ "local"
10 / Microsoft OneDrive
   \ "onedrive"
11 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
12 / Yandex Disk
   \ "yandex"
Storage>
When you see this text, press ‘4’ and then ENTER.
Leave the next two questions blank. Rclone will print out a URL which you may then visit with a web browser. After logging in with your cloud storage credentials, you will see a code. Copy the code into your terminal to complete the Rclone configuration process. This pass will be required for every cloud storage system you want to set up.

Testing Rclone

As you can see, the configuration process is very easy and fast. Now it’s time to ensure that you’ve done it correctly!
In my $HOME, I have a text file named “test.txt”. To test Rclone I will execute the command:
$ rclone copy $HOME/test.txt dropbox:
The program should copy it to my remote cloud storage.
This is the simplest case as we are dealing with only one file, but Rclone can also copy folders using this command:
$ rclone copy $HOME/Documents/ dropbox:Documents
Using this command the folder and all of it’s contents should be correctly copied.
It’s also possible to list the content of the remote folder, like this:
$ rclone ls dropbox:
or like this:
$ rclone lsl dropbox:
if you are dealing with lots of information in many stored files.
Rclone also has the ability to create new paths on remote folders. For example, with the following command:
$ rclone mkdir dropbox:/unixmen/gmolica
you can transfer the whole structure of folders to Dropbox, which will create the structure of folders under unixmen/gmolica
It’s also possible to sync two folders using this command:
$ rsync $HOME/Documents dropbox:/Documents
Note that this command will delete any file that exist in the source file but don’t exist in the destination file。
-----------------


在Debian/Ubuntu上使用rclone挂载Google Drive网盘

说个挂载Google Drive网盘的方法,毕竟Google Drive15G免费的空间,有的也有无限空间,都可以利用上去。

说明

本教程只适用Debian/Ubuntu系统,如果你是CentOS或者其它Linux系统,请使用以下命令安装rclone
curl https://rclone.org/install.sh | sudo bash

初始化配置和挂载方法和下面一样.

安装

1、安装rclone
2、初始化配置
rclone config
会出现以下信息:
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats  #随便填,后面要用到
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Box
   \ "box"
 5 / Cache a remote
   \ "cache"
 6 / Dropbox
   \ "dropbox"
 7 / Encrypt/Decrypt a remote
   \ "crypt"
 8 / FTP Connection
   \ "ftp"
 9 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
10 / Google Drive
   \ "drive"
11 / Hubic
   \ "hubic"
12 / Local Disk
   \ "local"
13 / Microsoft Azure Blob Storage
   \ "azureblob"
14 / Microsoft OneDrive
   \ "onedrive"
15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
16 / Pcloud
   \ "pcloud"
17 / QingCloud Object Storage
   \ "qingstor"
18 / SSH/SFTP Connection
   \ "sftp"
19 / Webdav
   \ "webdav"
20 / Yandex Disk
   \ "yandex"
21 / http Connection
   \ "http"
Storage> 10  #选择10,Google Drive
Google Application Client Id - leave blank normally.
client_id>  #留空 
Google Application Client Secret - leave blank normally.
client_secret>  #留空
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> n  #选择n
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth....  #复制到浏览器打开,获取验证码
Log in and authorize rclone for access
Enter verification code>  #填入上面获取到的验证码
Configure this as a team drive?
y) Yes
n) No
y/n> y  #选择y
Fetching team drive list...
No team drives found in your account--------------------
[Rats]
client_id = 
client_secret = 
service_account_file = 
token = {"access_token":"ya29.GltFBd7UJN2qrxdG8FnG_rMuB18ogb8QlujdL7glvXtfV"}
team_drive = 
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  #选择y
Current remotes:

Name                 Type
====                 ====
Rats                 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退出
3、挂载为磁盘
#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/GoogleDrive
#挂载为磁盘
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
DriveName为初始化配置填的nameFolderGoogle Drive里的文件夹,LocalFolderVPS上的本地文件夹。
挂载成功后,输入df -h命令查看即可!
4、卸载磁盘
fusermount -qzu LocalFolder
设置自启 使用命令:
#Debian系统
apt-get install sudo -y

#设置自启
mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
update-rc.d -f rcloned defaults
bash /etc/init.d/rcloned start
检测信息显示'rclone启动成功'即可。
-----------------

在Debian/Ubuntu上使用rclone挂载OneDrive网盘

提示:本教程挂载OneDrive for Business和个人版的方法都一样,这里以个人版为参考。

说明

本教程只适用Debian/Ubuntu系统,如果你是CentOS或者其它Linux系统,请使用以下命令安装rclone
curl https://rclone.org/install.sh | sudo bash
客户端授权、初始化配置和挂载方法和下面一样.

客户端授权

在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/。然后解压出来,比如我解压到D盘,文件夹命名rclone,此时点击Win+R,然后输入cmd,确定。再输入以下命令:
cd /d d:\rclone
rclone authorize "onedrive"
会出现以下信息:
C:\Users\Administrator>cd /d d:\rclone

d:\rclone>rclone authorize "onedrive"
2018/01/23 20:28:56 NOTICE: Config file "C:\\Users\\Administrator\\.config\\rclo
ne\\rclone.conf" not found - using defaults
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p  #这里选择个人版,你想挂载Business就选择b
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
Paste the following into your remote machine --->
{"access_token":"xxxx"}  #请复制{xx}整个内容,后面需要用到
<---End paste

安装rclone

本教程只适用Debian/Ubuntu系统,如果你是CentOS,请参考:https://rclone.org/install/,安装rclone。挂载方法和下面差不多。
1、安装rclone
2、初始化配置
rclone config
会出现以下信息:
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats  #随便填,后面要用到
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Box
   \ "box"
 5 / Cache a remote
   \ "cache"
 6 / Dropbox
   \ "dropbox"
 7 / Encrypt/Decrypt a remote
   \ "crypt"
 8 / FTP Connection
   \ "ftp"
 9 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
10 / Google Drive
   \ "drive"
11 / Hubic
   \ "hubic"
12 / Local Disk
   \ "local"
13 / Microsoft Azure Blob Storage
   \ "azureblob"
14 / Microsoft OneDrive
   \ "onedrive"
15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
16 / Pcloud
   \ "pcloud"
17 / QingCloud Object Storage
   \ "qingstor"
18 / SSH/SFTP Connection
   \ "sftp"
19 / Webdav
   \ "webdav"
20 / Yandex Disk
   \ "yandex"
21 / http Connection
   \ "http"
Storage> 14  #选择14,Microsoft OneDrive
Microsoft App Client Id - leave blank normally.
client_id>  #留空 
Microsoft App Client Secret - leave blank normally.
client_secret>  #留空 
Remote config
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p  #这里选择个人版,你想挂载Business就选择b
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n  #选择n
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
    rclone authorize "onedrive"
Then paste the result below:
result> {"access_token":""}  #输入之前在客户端授权的内容
--------------------
[Rats]
client_id = 
client_secret = 
token = {"access_token":""}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  选择y
Current remotes:

Name                 Type
====                 ====
Rats                 onedrive

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退出

挂载

1、挂载为磁盘
#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/OneDrive
#挂载为磁盘
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
DriveName为初始化配置填的nameFolderOneDrive里的文件夹,LocalFolderVPS上的本地文件夹。
如果挂载过程中出现NOTICE: One drive root 'test': poll-interval is not supported by this remote错误,可以无视该错误。
挂载成功后,输入df -h命令查看即可!
2、卸载磁盘
fusermount -qzu LocalFolder最后我们就可以利用OneDrive for BusinessLinux VPS增加5TB的空间了。
-----------------

使用 rclone 来实时备份网站服务器数据

倾向于实时备份,这样的话还能启动另外一个VPS来做热备份。
一通寻找之下发现了rclone,rclone不是一个存储服务,而是整合了很多的存储平台,然后提供统一的接口,能提供更加复杂的备份逻辑,而且也不与任何实际的存储服务相耦合,便于在各个平台之间迁移,也算是一个神器了吧。

在容器中运行rclone

首先创建一个目录用于存放rclone数据,免得容器挂了之后还要重新配置



1
sudo mkdir -p /home/rclone

启动rclone容器



1
2
3
4
5
6
7
8
9
docker run \
 --name rclone \
 -d \
 --restart always \
 --cpus 0.2 \
 --mount type=bind,src=/etc/localtime,dst=/etc/localtime,readonly \
 --mount type=bind,src=/data/,dst=/data,readonly \
 --mount type=bind,src=/home/rclone/,dst=/root/ \
 newnius/rclone

假设你的VPS数据目录是/data
尽管rclone的sync是单向的,但是为了数据安全性,还是选择让容器只读

配置远程存储




1
docker exec -it rclone rclone config

输入n来新增一个远程存储;
给新存储指定一个名字,名字随意,为了方便区分,这里输入dropbox
选择远程存储类型,输入8选择Dropbox,随着rclone不断升级,这里的序号可能会变;
id 和 secret 留空,高级设置选n,自动配置选y
会看到请在浏览器中访问页面的提示;


因为VPS是没有桌面的,而且docker容器中就更不可能有桌面了,官方推荐是在另外的机器上(自己的电脑啥的)生成授权码,不过我感觉这样太麻烦了,除了本机要装rclone之外,还需要本地中端能访问dropbox,国内这烂环境,而且mac下也很难配置全局代理,所以换了一种方式。
根据OAuth2协议,客户端生成一个跳转链接,在目标站点完成授权后再次跳转到回调链接即可。根据这个特点。我们只要拿到这两个链接,然后授权这一步在本地浏览器上做就行,浏览器设置代理就太容易了。
首先获取客户端跳转链接,在VPS上打开另一个终端



1
docker exec -it rclone curl http://127.0.0.1:53682/auth


会看到返回了一串html代码,把href参数中的链接复制出来(也就是双引号中间的部分),这个链接被编码过了,直接访问会解析参数错误,所以需要先解码,这里使用了站长工具的UrlDecode。把链接复制进去,然后点击解码,再把结果链接复制,然后浏览器打开,选择accept。
然后会跳转到一个新的页面,浏览器提示链接拒绝,复制地址栏的链接,在VPS上终端下访问,完成OAuth2授权(服务器需要能够直连dropbox)



1
docker exec -it rclone curl "http://localhost:53682/?state=xxxxx"

把地址换成你自己的
双引号是必须的,否则在shell下会解析错误

不出意外,就能看到 All done. Please go back to rclone 输出了。
回到刚刚的终端下,会看到已经授权成功,然后选择y一切正常,再输入q退出配置。

至此,rclone的配置和授权就完成了,接下来要配置一下同步/备份策略。

设置备份策略

因为每个人的备份策略不一样,所以镜像中没有默认开启备份,需要自己编写
在启动容器时,会自动复制一个默认的备份脚本到 /home/rclone/sync.sh,这个脚本什么也不干。
首先要修改权限,否则普通用户无法修改。



1
sudo chmod 777 /home/rclone/sync.sh

根据你自己的需求,修改 /home/rclone/sync.sh文件



1
2
3
4
5
6
7
while true; do

  rclone sync /data/ dropbox:/ --local-no-check-updated --ignore-size --ignore-checksum

  sleep 300

done

由于rclone的sync目前仍不支持后台进程,从而自动同步修改的文件,所以需要自己在文件变动后再次执行sync,所以我是把同步任务放到了无限循环里,rclone在同步时会自动忽略相同的文件。
根据数据的不同,如果是数据库文件的话,变化频繁而且文件内容大,实时备份会消耗占用较大的流量。可以设置一定的备份间隔,减少流量消耗。
由于是热备份,在备份过程中文件可能会被修改,为了保持一致性,rclone会拒绝同步该部分文件,可以通过添加后面的三个参数来忽略这些错误,继续备份这些文件。
修改完毕之后,重启容器,开始执行备份任务



1
docker restart rclone

可以在dropbox网页端看到文件已经在同步了。

参考

---------------------------

Linux下,安装Rclone,挂载Google Drive、OneDrive、WebDAV、FTP等等;互相拷贝、备份文件等


Rclone,Linux下,可挂载Google Drive、OneDrive、WebDAV、FTP等等,堪称神器。下面是安装和使用教程。
一、安装Rclone
下面的操作基于Centos系统
1、安装必须的应用
yum -y install wget unzip screen fuse fuse-devel
2、安装Rclone
curl https://rclone.org/install.sh | sudo bash
或者
wget https://downloads.rclone.org/rclone-current-linux-amd64.zip 
unzip rclone-current-linux-amd64.zip
mv rclone-v* rclone
cd rclone
二、挂载Google Drive
1、挂载GDrive
rclone config
选择 n ,创建新链接,并命名为 gdrive 。然后选择Google Drive.
client_id、client_secret 留空直接回车,SCOPE 选1,root_folder_id、service_account_file留空回车,Edit advanced config、Use auto config 选择n
这时,会出现个链接,复制到浏览器中,获取授权代码,并把授权代码粘贴到终端。
根据提示选择,一般为n、y、q
把Google Drive挂载到服务器上的一个目录。为便于以后web访问,可挂载到/www/wwwroot/下(以下演示为/www/wwwroot/gdrive.xxx.com,gdrive.xxx.com改为自己的域名)
./rclone mount gdrive: /www/wwwroot/gdrive.xxx.com --allow-other --allow-non-empty --vfs-cache-mode writes
2、设置开机启动rclone
先把rclone的可执行文件复制到/usr/bin:
cp /root/rclone/rclone /usr/bin/rclone
新建一个rclone.service文件:
vi /usr/lib/systemd/system/rclone.service
粘贴:
[Unit]
Description=rclone
    
[Service]
User=root
ExecStart=/usr/bin/rclone mount gdrive: /www/wwwroot/gdrive.xxx.com --allow-other --allow-non-empty --vfs-cache-mode writes
Restart=on-abort
    
[Install]
WantedBy=multi-user.target
重载daemon,让新的服务文件生效:
systemctl daemon-reload
启动rclone:
systemctl start rclone
设置开机启动:
systemctl enable rclone
三、Rclone的操作
1、列出远程目录(gdrive为之前创建的)
rclone lsd gdrive
2、复制文件
rclone copy 源文件/目录 目标目录
源文件/目录、目标目录要绝对路径,均可以为服务器、网盘等
如要保存别人分享的Gdrive,可先保存到自己的网盘,然后复制这些文件到自己的网盘,以免共享的人删除文件。
rclone copy gdrive:gongxiang/japan gdrive:gongxiang/self
3、同步文件
rclone sync 源文件/目录 目标目录
这个只同步没有的文件。适合变化较大的文件。
-----------------------------

How to Use rclone to Back Up to Google Drive on Linux


There’s still no official Linux client for Google Drive, but you can back up to your Google Drive using the rclone utility right from the command line. We show you how.
ADVERTISEMENT

Where’s Google Drive on Linux?

Despite promising Linux support “coming soon” back in 2012, there’s no indication that Google will ever produce a native Linux client for Google Drive. There are several unofficial third-party solutions, such as InSyncoverGrive and ODrive, and some file browsers allow integration with your Google Drive, such as Files in GNOME.
The third-party applications are commercial products, requiring either an outright purchase or a subscription. They work well they don’t cost much, and in fact, overGrive does have a free version, offering limited functionality for no cost.
But what if you want to create and run backups from the command line? Or to incorporate that functionality into scripts? That’s all possible thanks to an amazing application called rclone. In fact, with rclone you can back up, download, and synchronize files to over forty different cloud solutions. It’s like rsync for clouds.

Installing rclone

rclone almost certainly won’t be installed on your Linux computer by default. Happily, there’s an installation script that should work on all distributions. The installation process uses curl. On the computers used to research this article, Fedora 31 and Manjaro 18.1.0 already had curl installed but  curl had to be installed on Ubuntu 18.04 LTS.
On Ubuntu, run this command to install it:
sudo apt-get install curl
sudo apt-get install curl in a terminal window
Once curl has been installed, install rclone with this command:
curl https://rclone.org/install.sh | sudo bash
curl https://rclone.org/install.sh | sudo bash in a terminal window
When the rclone installation has finished, you’ll see a success message.
Success message from the rclone installtion script in a terminal window
This has installed the rclone program on your Linux computer. The next step is to run through the setup process and authenticate rclone to access your Google Drive.

Creating an rclone Remote Connection

Connections to remote cloud services are called “remotes” in the rclone world. We need to create one for Google Drive. Start the rclone configuration process with this command:
rclone config
rclone config in a terminal window
There are a lot of questions in the configuration process. But don’t be disheartened, many of them can be left at their default values and simply accepted by pressing “Enter.”
rclone tells us there are no remotes configured. Press “n” and press “Enter” to create a new remote. It will prompt you for a name. We’re going to call it “google-drive.” Use whatever name you like.
rclone menu to create a new remote, in a terminal window
A long menu allows you to choose the type of storage you’re creating a remote connection to.
rclone remote connection type menu in a terminal window
Scroll through the list until you see the entry for Google Drive, and make a note of its number.
rclone config in a terminal window
We can see that in this instance, it is number 13. Enter this as the storage type and press “Enter.”
Setting the rclone storage type in a terminal window
You’re prompted for a Google Application Client ID. Press “Enter” to accept the default.
Prompt for a Google application client id in a terminal window
You’re then prompted for a Google Application Client Secret.
prompt for a Google application client secret in a terminal window
Again, just press “Enter.” You’re asked to provide the scope that rclone will have when it is operating on your Google Drive. Press “1” and then press “Enter.”
providing the scope for rclone in a terminal window
For the “ID of the root folder”, just press “Enter.”
prompt for root folder ID ina terminal window
At the “Service Account Credentials” prompt, press “Enter.”
Prompt for Service Account Credentials in a terminal window
At the “Edit advanced config”  prompt, just press “Enter.” At the “Use auto config” menu, press “y” and then press “Enter.”
The "use auto config" menu in a terminal window
This causes rclone to communicate to your Google Drive, and to launch your browser to allow you to give permission for rclone to interact with your Google Drive.
rclone about to launch a browser, in a terminal window
In your browser window, click on the Google account you wish to use.
Choosing the Google account to use in a browser window
Click the “Allow” button to allow rclone to have access to your Google Drive.
Allowing rclone to work with Google Drive in a terminal window
When authenticate has completed, you’ll see a “Success!” message in the browser window. You can close the browser and return to the terminal window.
Success message in a browser window
At the “Configure this as a team drive” prompt, type “n” and then press “Enter.”
The rclone "configure this as a team drive" prompt in a terminal window
At the “Yes, Edit, Delete” menu type “y” and then press “Enter.”
The rclone "yes,edit, delete" menu in a terminal window
At the final menu, type “q” and press “Enter.”
The rclone final menu in a terminal window

The rclone Back Up Script

The rclone application is very feature-rich. That’s great, but it does mean there are a lot of options. The command we’re going to look at below copies files from your local computer to your Google Drive. This is a one-way copy to the cloud; it isn’t a two-way synchronization between your Google Drive and your local computer—although rclone can do that. We’re using this as a basic form of off-site backup.
Type (or copy and paste) this into a text editor and save it to your computer. We called it gbk.sh. You can call it whatever makes sense to you.
#!/bin/bash

/usr/bin/rclone copy --update --verbose --transfers 30 --checkers 8 --contimeout 60s --timeout 300s --retries 3 --low-level-retries 10 --stats 1s "/home/dave/Documents" "google-drive:LinuxDocs"
Here’s what the parameters mean:
  • copy: Copy the files from the local computer to the remote storage, skipping over files that are already present on the remote storage.
  • –update: Skip any files that are on the remote storage that have a modified time that is newer than the file on the local computer.
  • –verbose: Gives information about every file that is transferred.
  • –transfers 30: This sets the number of files to copy in parallel.
  • –checkers 8: How many “checkers” to run in parallel. Checkers monitor the transfers that are in progress.,
  • –contimeout 60s: The connection timeout. It sets the time that rclone will try to make a connection to the remote storage.
  • –timeout 300s: If a transfer becomes idle for this amount of time, it is considered broken and is disconnected.
  • –retries 3: If there are this many errors, the entire copy action will be restarted.
  • –low-level-retries 10: A low-level retry tries to repeat one failing operation, such as a single HTTP request. This value sets the limit for the number of retries.
  • –stats 1srclone can provide statistics on the transferred files. This sets the frequency of update of the statistics to one second.
  • “/home/dave/Documents”: The local directory to we’re going to copy to the remote storage.
  • “google-drive:LinuxDocs”: The destination directory in the remote storage. Note the use of “google-drive”, which is the name we gave to this remote connection during the the rclone config sequence. Also note the colon “:” that is used as a separator between the remote storage name and the directory name. Subdirectories are separated by the usual “/” forward slash. If the destination directory does not exist, it will be created.
Some of these values are the defaults, but we’ve included them here so that we can discuss them. That way, if you need to change a value, you know which parameter to adjust.
Make the script executable with this command:
chmod +x gbk.sh

Running the Back Up Script

Our back up script is going to copy our Documents folder to our Google Drive. In our Documents folder, we’ve got a collection of sheet music.
Collection of sheet music in ~/Documents in a file browser
We can launch the back up script with this command:
./gbk.sh
./gbk.sh in a terminal window
We asked for statistics updates every one second (--stats 1s), and we also asked for verbose output (--verbose). It’ll come as no surprise then that we get a lot of screen output. It’s usually a good option to turn on verbose output for new functionality so that you can spot problems. You can turn down the amount of output once you’re happy things are running smoothly.
rclone output in a terminal window
We get a final summary telling us 60 files were transferred with no errors. The transfer took roughly 24 seconds.
Let’s check on our Google Drive and see what happened in our cloud storage.
LinuxDocs folder in Google Drive
A “LinuxDocs” directory has been created, so that looks promising. If we double-click it to take a look inside, we can see that the files have all been transferred to our Google Drive.
Files in "LinuxDocs" on Google Drive

Using rclone to View Files On Google Drive

We can use rclone to peek into the folder on Google Drive, right from the terminal window:
rclone ls google-drive:/LinuxDocs
rclone ls google-drive:/LinuxDocs in a terminal window

The Tip of the Iceberg

That’s great that we can perform this type of copy straight from the command line. We can incorporate the use of our cloud storage into scripts, and we could schedule the execution of back up scripts using cron.
rclone has an absolute wealth of commands, you’re encouraged to check out their documentation and excellent website. We’ve barely scratched the surface here, and a bit of reading and playing with rclone will pay back the effort many times over.
Strictly speaking, this isn’t a true backup. It is an off-site, remote copy of your files and data, which is definitely a good thing to have, but it is just a copy of files. It doesn’t offer versioning or other features that true backup solutions would offer.
So use rclone in conjunction with other backup techniques. As another layer to an existing backup regime rclone is an easy way to get your data stored in a location that is geographically removed from your home or office. And that’s got to be a good thing.
https://www.howtogeek.com/451262/how-to-use-rclone-to-back-up-to-google-drive-on-linux/
-------
https://github.com/rclone/rclone
https://github.com/mawaya/rclone
(https://github.com/mawaya/rclone/releases) 
https://github.com/donwa/gclone
--------
一个接gclone后续的简单脚本.

gd

一个接gclone后续的简单脚本

主要功能:

简化转存操作

提取分享链接文件夹,交互式选择保存位置

使用前提:

gclone配置好。

网上教程很多,自行搜索

使用:

sh -c "$(curl -fsSL https://git.io/gd.sh)" 
from https://github.com/vcfe/gd
--------
rclone GUI, qBittorrent and rTorrent on Google Colaboratory.
https://minormole.github.io/RcloneLab

What's new in RcloneLab 2.0?

  • Add rTorrent+Flood as an alternative torrent client; It has a beautiful UI and unique traits from qBittorrent.
  • Add Ubuntu Virtual Machine Updater.
  • Change output from text to HTML; more beautiful and easier to use.
  • Remove support for loading rclone.conf from Google Drive.
  • Code performance and logic improvement.
  • Fix can't use F5 when to enter qBittorrent WebUI for the first time.

Introduction

RcloneLab is a rclone GUI for Google Colaboratory, similar to Rclone Browser. Please consider contributing our project, any improved version of the code is welcome and much appreciate.

qBittorrent is a cross-platform free and open-source BitTorrent client.

Flood is a monitoring service for rTorrent BitTorrent client.

Google Colaboratory is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud with high speed network. Check the VM's specification here.

Installation Open In Colab

  1. Open the IPython Notebook file in Google Colaboratory by clicking here.

  2. Click "Run cell" (play button) and follow the instruction that show in the output.

    Tip

    We recommend to use Rclone Browser for file browsing and get path for RcloneLab.

    from  https://github.com/acamposxp/RcloneLab 

    -------------------

    利用 Rclone备份 VPS 数据到 onedrive

    数据无价,时常备份服务器中的数据是良好的习惯。Rclone (“rsync for cloud storage”) 是一个命令行程序,用于将文件、目录与不同云存储提供商进行同步。利用 Rclone备份 VPS中的数据到onedrive、google drive等云盘中,保障我们的数据安全。

    Github地址

    https://github.com/rclone/rclone

    准备onedrive的授权

    准备一个rclone支持的云盘账户,我这里选用的是onedrive,需要进行oendrive授权。

    Rclone下载页面下载与自己电脑系统对应的程序,我这里选择的是macOS-ARM-64 Bit

    将软件下载到Downloads(下载)文件夹后,解压,并修改文件夹名字为rclone

     Mac上打开软件Terminal(终端),输入以下命令:

cd Downloads/rclone  # Downloads/rclone 为解压文件的路径
./rclone authorize "onedrive" #如果提示错误,需要进 系统偏好-安全与隐私 中允许软件运行.
 成功后会自动弹出浏览器进入onedrive登录界面,授权完成后,在Terminal窗口可以看到授权码的出现,
将授权码复杂下来备用,需要包含大括号。
{"access_token":"EwCAA8l6BAAUwihrrCrmQ4wuIJX5mbj7rQla6TUAAS7oJFl1pmRc4whIlOj5am6oPQ+zf1kOcygsi5JHL2IgXh55prjh3r6P/asfdjkhasjkfd/kHywyZnEvM8kDr55B1J//SXLJ1sGNsNR9vH0Rmz9xMrnl6GFrF8z+UQxi+GL3L3MpBN3NenacA0+pmVXKk8hghj64a8xxEFhlc+b0LJCp4yMg+96548752OPQwLZEPikbJ1zB5Wm5IUzuq03zNKa5lOicGET0l8zWW+itYg2Ca+mCS9DRm5e8NcPL5yiLZmRIm4vCI3pIQGKxEKghQG2lLmjMnWJj8BMotxH9Px2/XWs2TJ3BdLbuX2EjdYy8MNoBbaYXafe3uHx!UpdOwFHCiKnJqYomn*8cCFNP7RM1W8DMzXNBAlgTnuaRo6v7xjxFX3xIrXWonyCk*l1Z7glOXEmRS","expiry":"2022-07-12T15:47:47.8171297+08:00"}

配置Rclone与onedrive连接

  1. 安装rclone,SSH进入VPS后,输入以下命令
curl https://rclone.org/install.sh | sudo bash
  1. 然后输入rclone config
  2. 由于刚安装还没有配置,在以下弹出的消息后选择n
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
  1. 为新创建的连接取一个名字,我这里选择backup2onedrive
Enter name for new remote.
name> backup2onedrive
  1. 然后选择自己要同步的网盘,这里选择了32(随着更新,数字可能会发生变化,请根据提示选择)
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
1 / 1Fichier
  \ (fichier)
2 / Akamai NetStorage
  \ (netstorage)
3 / Alias for an existing remote
  \ (alias)
4 / Amazon Drive
  \ (amazon cloud drive)
5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, China Mobile, Cloudflare, ArvanCloud, Digital Ocean, Dreamhost, Huawei OBS, IBM COS, IDrive e2, Lyve Cloud, Minio, Netease, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS and Wasabi
  \ (s3)
6 / Backblaze B2
  \ (b2)
7 / Better checksums for other remotes
  \ (hasher)
8 / Box
  \ (box)
9 / Cache a remote
  \ (cache)
10 / Citrix Sharefile
  \ (sharefile)
11 / Combine several remotes into one
  \ (combine)
12 / Compress a remote
  \ (compress)
13 / Dropbox
  \ (dropbox)
14 / Encrypt/Decrypt a remote
  \ (crypt)
15 / Enterprise File Fabric
  \ (filefabric)
16 / FTP
  \ (ftp)
17 / Google Cloud Storage (this is not Google Drive)
  \ (google cloud storage)
18 / Google Drive
  \ (drive)
19 / Google Photos
  \ (google photos)
20 / HTTP
  \ (http)
21 / Hadoop distributed file system
  \ (hdfs)
22 / HiDrive
  \ (hidrive)
23 / Hubic
  \ (hubic)
24 / In memory object storage system.
  \ (memory)
25 / Internet Archive
  \ (internetarchive)
26 / Jottacloud
  \ (jottacloud)
27 / Koofr, Digi Storage and other Koofr-compatible storage providers
  \ (koofr)
28 / Local Disk
  \ (local)
29 / Mail.ru Cloud
  \ (mailru)
30 / Mega
  \ (mega)
31 / Microsoft Azure Blob Storage
  \ (azureblob)
32 / Microsoft OneDrive
  \ (onedrive)
33 / OpenDrive
  \ (opendrive)
34 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
  \ (swift)
35 / Pcloud
  \ (pcloud)
36 / Put.io
  \ (putio)
37 / QingCloud Object Storage
  \ (qingstor)
38 / SSH/SFTP
  \ (sftp)
39 / Sia Decentralized Cloud
  \ (sia)
40 / Storj Decentralized Cloud Storage
  \ (storj)
41 / Sugarsync
  \ (sugarsync)
42 / Transparently chunk/split large files
  \ (chunker)
43 / Union merges the contents of several upstream fs
  \ (union)
44 / Uptobox
  \ (uptobox)
45 / WebDAV
  \ (webdav)
46 / Yandex Disk
  \ (yandex)
47 / Zoho
  \ (zoho)
48 / premiumize.me
  \ (premiumizeme)
49 / seafile
  \ (seafile)
Storage> 32
  1. Client ID不需要填写,直接 回车
OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>
  1. Client Secret也不需要填写,直接 回车
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>
  1. 选择OneDrive服务器区域,我使用用的是国际版输入1,如果使用的是世纪互联,那就输入4
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own value
1 / Microsoft Cloud Global
  \ "global"
2 / Microsoft Cloud for US Government
  \ "us"
3 / Microsoft Cloud Germany
  \ "de"
4 / Azure and Office 365 operated by 21Vianet in China
  \ "cn"
region> 1
  1. 高级配置,选择 n
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n
  1. 自动配置,也选择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
  1. 提示输入授权码,这时候将之前准备的授权码输入(记得包含大括号)。
Enter a string value. Press Enter for the default ("").
config_token> {"access_token":"EwCAA8l6BAAUwihrrCrmQ4wuIJX5mbj7rQla6TUAAS7oJFl1pmRc4whIlOj5am6oPQ+zf1kOcygsi5JHL2IgXh55prjh3r6P/asfdjkhasjkfd/kHywyZnEvM8kDr55B1J//SXLJ1sGNsNR9vH0Rmz9xMrnl6GFrF8z+UQxi+GL3L3MpBN3NenacA0+pmVXKk8hghj64a8xxEFhlc+b0LJCp4yMg+96548752OPQwLZEPikbJ1zB5Wm5IUzuq03zNKa5lOicGET0l8zWW+itYg2Ca+mCS9DRm5e8NcPL5yiLZmRIm4vCI3pIQGKxEKghQG2lLmjMnWJj8BMotxH9Px2/XWs2TJ3BdLbuX2EjdYy8MNoBbaYXafe3uHx!UpdOwFHCiKnJqYomn*8cCFNP7RM1W8DMzXNBAlgTnuaRo6v7xjxFX3xIrXWonyCk*l1Z7glOXEmRS","expiry":"2022-07-12T15:47:47.8171297+08:00"}
  1. Rclone连接到onedrive网盘,输入y确认。
Drive OK?
Found drive "root" of type "personal"
URL: https://onedrive.live.com/?cid=a50d72ae9
y) Yes (default)
n) No
y/n> y
  1. 配置完成后,显示所有信息,选择 y 确认。
[backup2onedrive]
type = onedrive
token = {"access_token":...
drive_id = a50d72ae9
drive_type = personal
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
  1. 完成后程序退回到了初始命令处,输入 q 退出。
Current remotes:
Name                 Type
====                 ====
backup2onedrive     onedrive
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

编写 Rclone备份 脚本

  1. 首先确定你需要同步的文件夹,我这里选择的是/home/backup
  2. SSH进入VPS,目前我的路径为/root
  3. 输入以下命令创建脚本
vim backup.sh
  1. 按一下键盘上的 i,进入编辑模式。并输入以下内容。其中/home/backup为VPS上需要备份的文件夹,backup/backup_for_vps为onedrive上的存放路径。需要注意的是,下面的命令为同步,即如果backup/backup_for_vps下有其他文件,同步完成后会被抹除,只剩下VPS同步过去的文件。所以建议路径指向onedrive中的一个空文件夹。
#!/bin/bash
rclone sync /home/backup backup2onedrive:backup/backup_for_vps
  1. 完成编写后,按键盘Esc后输入:wq即可保存并退出编辑。
  2. 为创建的脚本赋予执行权限
chmod +x backup.sh
  1. 此时如果输入./backup.sh即可运行该脚本,并完成文件的同步。但是我们需要设置一个定时任务,让脚本以指定频率自动运行。输入以下命令
crontab -e
  1. (如果弹出指令,让你选择编辑工具,选择vim,)进入到定时任务的编辑文件后,按一下键盘上的 i,进入编辑模式。并在最后一行,加入以下内容。前面五个星号的位置可以修改 * * * * *,从前往后分别对应 分钟(0-59 小时(0-23 一个月中第几天(1-31 月份(1-12 星期(0-6
30 2 * * 2,4,6  /root/backup.sh >> /root/backup.log 2>&1 #周二、四、六的凌晨2点30分运行脚本,并将运行日志记录到backup.log中
  1. 完成后,即可在指定时间结束后,在onedrive中查看备份的结果。建议时不时上onedrive中查看同步的结果,避免Rclone出错未成功备份数据。

--------------------------------------------------------------

Rclone安装配置教程: 挂载OneDrive同步文件

 

1. 准备工作

在教程开始之前,首先要做一些准备工作,主要有三点。

首先就是注册一个OneDrive网盘账号,如果你已经有了可以忽略这点。其次是利用宝塔面板备份网站数据到服务器磁盘。最后是一句话带你认识Rclone这个软件,Rclone是个非常强大的云存储文件管理命令行程序。

2. 安装Rclone

Rclone安装非常简单,远程登录VPS服务器后,只需执行一条命令:

curl https://rclone.org/install.sh | sudo bash

安装成功后的提示如下。

rclone v1.56.0 has successfully installed.
Now run "rclone config" for setup. Check https://rclone.org/docs/ for more details.

3. OneDrive授权

这一步是在本地电脑Windows系统操作,进入Rclone下载页面,点击下载Windows版本的Rclone软件,选择Intel/AMD-64Bit即可。如果是32位操作系统,那么选择32Bit的。

下载后将全部文件解压到D:\rclone文件夹,打开CMD命令窗口,依次输入下面两条命令。

cd /d d:\rclone
rclone authorize "onedrive"

第二条命令输入完回车后会自动打开浏览器,登录你的OneDrive账号,点击“是”按钮同意授权。成功后返回到CMD命令窗口就能看到长串授权码,即花括号以及里面的内容。

将授权码复制下来保存备用,有效期1个小时。

Paste the following into your remote machine --->
{"access_token":"EwCAA8l6BAAUwihrrCrmQ4wuIJX5mbj7rQla6TUAAS7oJFl1pmRc4whIlOj5am6oPQ+zf1kOcygsi5JHL2IgXh55prjh3r6P/fSZr8K9UJ58Pksh1YTJkzL/kHywyZnEvM8kDr55B1J//SXLJ1sGNsNR9vH0Rmz9xMrnl6GFrF8z+UQxi+GL3L3MpBN3NenacA0+pmVXKk8hghj64a8xxEFhlc+b0LJCp4yMg+96548752OPQwLZEPikbJ1zB5Wm5IUzuq03zNKa5lOicGET0l8zWW+itYg2Ca+mCS9DRm5e8NcPL5yiLZmRIm4vCI3pIQGKxEKghQG2lLmjMnWJj8BMotxH9Px2/XWs2TJ3BdLbuX2EjdYy8MNoBbaYXafe3uHx!UpdOwFHCiKnJqYomn*8cCFNP7RM1W8DMzXNBAlgTnuaRo6v7xjxFX3xIrXWonyCk*l1Z7glOXEmRS","expiry":"2021-09-16T15:47:47.8171297+08:00"}
<---End paste

4. 配置Rclone

和安装相同,Rclone配置也只需要一条命令。不同的是后续操作比较繁琐,需要有耐心哈。在配置过程中如果输错字母,可以按Ctrl+Backspace删除。

我们首先在VPS远程登录窗口输入下面命令:

rclone config

新建远程网盘连接,输入字母n回车。

No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n

给远程网盘起个名字,因为我是RackNerd服务器备份到OneDrive网盘,输入名称rn2od

name> rn2od

接着会出现一系列网盘名字列表,我输入26选择OneDrive网盘。需要注意的是这个序号以后可能会有变动,填写的时候再次确认下。

Storage> 26

Client ID无需设置,直接回车使用默认的。

OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>

Client Secret也不用填写,回车使用默认值。

OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> 

选择OneDrive网盘服务器的区域,我用的是国际版输入1,如果你用的是世纪互联,那就输入4

Choose national cloud region for OneDrive.
Choose a number from below, or type in your own value
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
region> 1

不需要设置高级配置,输入n后回车

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n

因为我们是远程连接VPS主机,不能自动配置,填写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

这时候将第二步获取的OneDrive授权码粘贴到config_token>后面,回车。

Enter a string value. Press Enter for the default ("").
config_token> 

选择OneDrive网盘,输入1

Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
config_type> 1

Rclone找到一个OneDrive盘,输入y确定回车。

Drive OK?
Found drive "root" of type "personal"
URL: https://onedrive.live.com/?cid=a40d32de9
y) Yes (default)
n) No
y/n> y

确认OneDrive网盘的所有信息,输入y回车。

[rn2od]
type = onedrive
token = {"access_token":"EwBoA8l6BAAU6k7qJd7*3wELXHy...
drive_id = a40d32de9
drive_type = personal
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y

配置完成后Rclone显示远程网盘列表,至此配置结束,输入q退出。

Current remotes:
Name                 Type
====                 ====
lh2od                onedrive
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

经过上面的设置后,我们就成功地将Rclone连接挂载到OneDrive网盘啦。

5. 编写同步脚本

这个脚本也不算麻烦,首先输入下方命令新建同步脚本。

vi rclone.sh

按Insert键进入编辑模式,粘贴以下三条内容。

#!/bin/bash
rclone sync /www/backup/database rn2od:rnbak/database
rclone sync /www/backup/site rn2od:rnbak/site

然后按Esc键退出编辑模式,输入:wq保存并退出。

脚本首行是注释,上面的脚本只包含两条命令,第二行是将/www/backup/database目录及里面的数据库备份文件,同步到OneDrive的rnbak/database文件夹里。第三行是同步网站备份文件。

接着为新建的脚本增加执行权限。

chmod +x rclone.sh

6. 设置定时任务

脚本编写成功后,需要设置定时任务来运行脚本,才能完成自动备份。

在设置之前,首先将VPS服务器的时区设置为东八区,与我们的作息相同。如果你是国内的VPS或云服务器通常不需要设置。

cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime

输入y确定。

接下来我们设置定时任务,输入下方命令。

crontab -e

按Insert键进入编辑模式,在尾部添加一行即可。

35 1 * * *  /root/rclone.sh >> /root/rclone.log 2>&1

这行内容的意思是,每天凌晨1点35分,运行rclone.sh脚本,将网站和数据库备份文件同步到OneDrive网盘。

然后等到第二天,登录OneDrive盘就能看到备份文件已经同步过来了。

好了以上就是利用Rclone程序,将网站和数据库备份文件同步到OneDrive网盘的教程。这样VPS服务器和网盘都有网站备份,双重备份更安全。如果你不放心,还可以每周将Onedrive网盘里的文件手动下载到本地电脑。

最后再提醒下,建议每隔一段时间去Onedrive盘查看一下同步是否正常,因为即使是Rclone程序也有可能出问题。

----------------

Rclone Synchronizes Files Between Multiple Cloud Storage Services (Command Line)

There are command line tools available for synchronizing files from / to cloud storage services, but they usually only support one service. Like Grive2 for Google Drive, the official Yandex.Disk console client, Dropbox Uploader, and so on.

But what about synchronizing files and folders from or to multiple cloud storage services? For such cases, you can use Rclone, a Rsync-like program for cloud storage.

Rclone can synchronize files and directories between Google Drive, Google Cloud Storage, Dropbox, Microsoft One Drive, Amazon S3, Amazon Drive, Openstack Swift / Rackspace cloud files / Memset Memstore, Hubic, Yandex Disk, and Backblaze B2.

The synchronization can be done either directly between these services, or to / from your local filesystem.

The tool is useful for backup purposes, but it can also be used as a solution for cases in which there's no official sync client available on a certain platform (either GUI, command line, or both, like Google Drive or Microsoft One Drive on Linux).

Although, for the latter, it's important to mention that there's no real-time file monitoring, and the synchronization only happens on demand (you must run it manually or via a script, etc.).

Rclone features:
  • MD5/SHA1 hashes checked at all times for file integrity;
  • timestamps preserved on files;
  • partial syncs supported on a whole file basis;
  • copy mode to just copy new/changed files;
  • sync (one way) mode to make a directory identical;
  • check mode to check for file hash equality;
  • can sync to and from network, eg two different cloud accounts;
  • is available for Linux, Windows, Mac, FreeBSD, NetBSD, OpenBSD, Plan 9 and Solaris.

Besides being able to synchronize files and folders, Rclone can list remote objects, display the size of remote objects, create, remove, and delete remote objects, and dedupe (find duplicates and offers to delete all but one or rename them).

There are also options to limit the bandwidth, set the connection timeout, and much more. Check out the Rclone docs for more information.

Rclone seems pretty fast too. As an example, I did a quick test and Rclone was able to upload a 141 MB / 52 items folder to Google Drive in about 23 seconds, while Grive2 took about 64 seconds for the same folder, with a second test being roughly the same. Copying the same folder from Google Drive to Dropbox took about 40 seconds.

This can depend on multiple factors, like the Internet connection fluctuating, server load, and so on, so don't take my word for it and give it a try.

The Rclone webpage provides extensive documentation for how to use it, including how to authenticate it with each cloud storage service, so I won't get into details about this here. See rclone.org for more information.

Download Rclone

Download Rclone | The source code can be found on GitHub.

For how to install Rclone, either from source or using the Linux binary, see THIS page.

Update: you may also want to check out RcloneBrowser, a cross-platform Qt5 GUI for Rclone.
 
from http://www.webupd8.org/2016/08/rclone-synchronizes-files-between.html