首先是下载文件
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目录,反过来也可以
-----
安装rclone
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
In this tutorial, we will install, configure and test rclone on Debian 8.
Installation
‘Go’ installation
# apt install golang
$ echo $GOPATH
$ export GOPATH="$HOME/gopath/"
$ go get -u -v github.com/ncw/rclone
As the root, copy the binary to
/usr/local/bin
(or /usr/bin
):$ cd $GOPATH/bin # cp rclone /usr/local/bin
Rclone configuration
$ rclone config
No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q>
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.
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>
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
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:
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
It’s also possible to list the content of the remote folder, like this:
$ rclone ls dropbox:
$ rclone lsl dropbox:
Rclone also has the ability to create new paths on remote folders. For example, with the following command:
$ rclone mkdir dropbox:/unixmen/gmolica
unixmen/gmolica
$ rsync $HOME/Documents dropbox:/DocumentsNote 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 Drive
有15G
免费的空间,有的也有无限空间,都可以利用上去。说明
Debian
/Ubuntu
系统,如果你是CentOS
或者其它Linux
系统,请使用以下命令安装rclone
:curl https://rclone.org/install.sh | sudo bash
安装
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退出
#新建本地文件夹,路径自己定,即下面的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
为初始化配置填的name
,Folder
为Google Drive
里的文件夹,LocalFolder
为VPS
上的本地文件夹。df -h
命令查看即可!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
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
为初始化配置填的name
,Folder
为OneDrive
里的文件夹,LocalFolder
为VPS
上的本地文件夹。
如果挂载过程中出现NOTICE: One drive root 'test': poll-interval is not supported by this remote
错误,可以无视该错误。
挂载成功后,输入df -h
命令查看即可!
2、卸载磁盘
fusermount -qzu LocalFolder
最后我们就可以利用OneDrive for Business
为Linux VPS
增加5TB
的空间了。
使用 rclone 来实时备份网站服务器数据
在容器中运行rclone
1
| sudo mkdir -p /home/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 |
尽管rclone的sync是单向的,但是为了数据安全性,还是选择让容器只读
配置远程存储
1
| docker exec -it rclone rclone config
|
n
来新增一个远程存储;给新存储指定一个名字,名字随意,为了方便区分,这里输入
dropbox
;选择远程存储类型,输入
8
选择Dropbox
,随着rclone不断升级,这里的序号可能会变;id 和 secret 留空,高级设置选
n
,自动配置选y
;会看到请在浏览器中访问页面的提示;
1
| docker exec -it rclone curl http://127.0.0.1:53682/auth
|
1
| docker exec -it rclone curl "http://localhost:53682/?state=xxxxx"
|
双引号是必须的,否则在shell下会解析错误
All done. Please go back to rclone
输出了。y
一切正常,再输入q
退出配置。设置备份策略
/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 |
1
| docker restart rclone
|
参考
Linux下,安装Rclone,挂载Google Drive、OneDrive、WebDAV、FTP等等;互相拷贝、备份文件等
下面的操作基于Centos系统
yum -y install wget unzip screen fuse fuse-devel
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
rclone config
根据提示选择,一般为n、y、q
./rclone mount gdrive: /www/wwwroot/gdrive.xxx.com --allow-other --allow-non-empty --vfs-cache-mode writes
cp /root/rclone/rclone /usr/bin/rclone
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
systemctl daemon-reload
systemctl start rclone
systemctl enable rclone
rclone lsd gdrive
rclone copy 源文件/目录 目标目录
如要保存别人分享的Gdrive,可先保存到自己的网盘,然后复制这些文件到自己的网盘,以免共享的人删除文件。
rclone copy gdrive:gongxiang/japan gdrive:gongxiang/self
rclone sync 源文件/目录 目标目录
How to Use rclone to Back Up to Google Drive on Linux
rclone
utility right from the command line. We show you how.Where’s Google Drive on Linux?
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.sudo apt-get install curl
curl
has been installed, install rclone
with this command:curl https://rclone.org/install.sh | sudo bash
rclone
installation has finished, you’ll see a success message.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
rclone
world. We need to create one for Google Drive. Start the rclone
configuration process with this command:rclone config
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
will have when it is operating on your Google Drive. Press “1” and then press “Enter.”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
to have access to your Google Drive.The rclone Back Up Script
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.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"
- 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 1s:
rclone
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.
chmod +x gbk.sh
Running the Back Up Script
./gbk.sh
--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.Using rclone to View Files On Google Drive
rclone
to peek into the folder on Google Drive, right from the terminal window:rclone ls google-drive:/LinuxDocs
The Tip of the Iceberg
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.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.gd
一个接gclone后续的简单脚本
主要功能:
简化转存操作
提取分享链接文件夹,交互式选择保存位置
使用前提:
gclone配置好。
网上教程很多,自行搜索
使用:
sh -c "$(curl -fsSL https://git.io/gd.sh)"
from https://github.com/vcfe/gd
--------
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 the IPython Notebook file in Google Colaboratory by clicking here.
-
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地址
准备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连接
- 安装rclone,SSH进入VPS后,输入以下命令
curl https://rclone.org/install.sh | sudo bash
- 然后输入
rclone config
- 由于刚安装还没有配置,在以下弹出的消息后选择
n
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
- 为新创建的连接取一个名字,我这里选择
backup2onedrive
Enter name for new remote.
name> backup2onedrive
- 然后选择自己要同步的网盘,这里选择了
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
- 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
- 自动配置,也选择
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
- 提示输入授权码,这时候将之前准备的授权码输入(记得包含大括号)。
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"}
- 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
- 配置完成后,显示所有信息,选择
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
- 完成后程序退回到了初始命令处,输入
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备份 脚本
- 首先确定你需要同步的文件夹,我这里选择的是
/home/backup
- SSH进入VPS,目前我的路径为
/root
。 - 输入以下命令创建脚本
vim backup.sh
- 按一下键盘上的
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
- 完成编写后,按键盘
Esc
后输入:wq
即可保存并退出编辑。 - 为创建的脚本赋予执行权限
chmod +x backup.sh
- 此时如果输入
./backup.sh
即可运行该脚本,并完成文件的同步。但是我们需要设置一个定时任务,让脚本以指定频率自动运行。输入以下命令
crontab -e
- (如果弹出指令,让你选择编辑工具,选择
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中
- 完成后,即可在指定时间结束后,在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)
The synchronization can be done either directly between these services, or to / from your local filesystem.
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.
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