WordPress的大多备份插件免费版只支持手动备份,并且只能下载至本地,自动备份到Google Drive等云盘需要订阅会员,花钱是不可能花钱的,那咱就只能用rclone来代替了
目录
安装
首先通过官方脚本安装rclone
$ sudo -v ; curl https://rclone.org/install.sh | sudo bash
完成后验证rclone安装完毕,查看rclone版本
$ rclone version
rclone v1.65.0
- os/version: ubuntu 22.04 (64 bit)
- os/kernel: 5.15.0-86-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.21.4
- go/linking: static
- go/tags: none
配置
接下来开始配置rclone
$ rclone config
首次配置会检查是否已存在配置文件,这里输入n来新建一个配置
2023/12/13 10:00:58 NOTICE: Config file "/home/ubuntu/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
这里要输入配置的名字,例如叫gd
Enter name for new remote.
name> gd
这里是选择使用哪个云盘,Google Drive的简称是drive,所以这里输入drive
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
...
Storage> drive
接下来要输入Google API凭据中的客户端ID以及客户端密钥,这个需要去Google API的控制台中创建,以后再说,也可以直接留空,这样会使用rclone默认的配置
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 value. Press Enter to leave empty.
client_id> ****
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret> ****
然后选择对云盘采取何种访问策略,一般选择1,也就是对云盘里所有文件具有读写权限
Option scope.
Comma separated list of scopes that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
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
这两个选项一般不用管,直接跳过
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 value. Press Enter to leave empty.
service_account_file>
Edit advanced config?
y) Yes
n) No (default)
y/n>
接下来是选择是否使用浏览器进行自动验证,由于远程服务器没有桌面环境,所以这里选择n
Use web browser to automatically authenticate rclone with remote?
* Say Y if the machine running rclone has a web browser you can use
* Say N if running rclone on a (remote) machine without web browser access
If not sure try Y. If Y failed, try N.
y) Yes (default)
n) No
y/n> n
这样就需要在一个有桌面环境的计算机上来获取认证token,下面以windows为例
在rclone官网下载页面上找到对应平台的可执行文件,下载到本地并解压,进入rclone可执行文件的文件夹,在这里打开cmd,回到远程服务器终端界面,找到这样一句话
rclone authorize "drive" "****"
复制这一句,然后粘贴在windows cmd中,并改为
> .\rclone.exe authorize "drive" "****"
这时会打开浏览器,并且需要登录Google账号进行认证。认证完毕之后cmd中会打印出认证token,将其复制下来
2023/12/13 11:13:56 NOTICE: Got code
Paste the following into your remote machine --->
************
<---End paste
如果出现i/o timeout
错误,说明没有为cmd设置代理,通过以下命令设置代理,将port
改为代理软件的监听端口,例如v2rayN默认的就是10809
> $Env:http_proxy=”http://127.0.0.1:port”;
> $Env:https_proxy=”http://127.0.0.1:port”;
设置完成后测试一下能否连接上Google,StatusCode是200的话就说明连接没有问题
> curl www.google.com
StatusCode : 200
StatusDescription : OK
回到远程服务器终端,粘贴刚才复制的认证token
config_token> **************
解析成功的话不会有提示,失败的话会打印Couldn't decode response - try again
,这时需要去检查是否复制完整,以及服务器端的rclone和windows端rclone的版本是否一致。
最后是设置是否配置为团队网盘,一般都是个人网盘,所以还是设置n
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n>
一切配置完毕,会让你选择保留配置或者重新设置,之前配置无误的话就输入y就行,有配置错的就输入e重新配置
Configuration complete.
Options:
- type: drive
- scope: drive
- team_drive:
Keep this "gd" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
然后就会回到rclone的初始配置界面,输入q退出
Current remotes:
Name Type
==== ====
gd 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
测试
接下来就可以测试一下rclone是否可用。先来扫描一下我Google Drive中的文件夹,例如我的Google Drive中只有一个叫wordpress_backup
的文件夹
$ rclone lsd gd:
-1 2023-12-13 11:22:31 -1 wordpress_backup
将打包好的wordpress备份文件上传至wordpress_backup
文件夹
$ rclone copy /var/www/main/wp-content/backups-dup-lite/20231213013025_archive.zip gd:wordpress_backup
上传速度取决于服务器的出网带宽,如果没有报错的话就是成功了,这时到Google Drive中查看,可以看到wordpress_backup
文件夹中多了一个20231213013025_archive.zip
文件
自动备份WordPress至Google Drive
待施工