AMH面板实现网站备份同步到google drive

查看 54|回复 2
作者:全球vps   
本帖首发于hostloc,转载请注明出处。
512内存vps安装amh面板,速度起飞,比起宝塔面板现在的臃肿,好的不是一点二点,amh面板实际操作下来,并不难用,但他给人的第一印象是很难入手,你说这是为什么呢?我想是大家习惯了使用宝塔吧,不多废话,直接进入主题。
优点:vps上挂载gd,不占用vps空间
最终实现:因为amh面板网站备份后只能ftp、ssh上传到其他vps备份,也没用这方面插件,此方法,挂载gd后,可以当做vps的本地盘,amh面板操作直接备份到gd云盘,当然你也可以做其他用途
期间有很多坑,自己一步一步填完了,不适合跳着看
一、获取google drive客户端ID和密钥
打开网址:
[ol]https://console.developers.google.com/[/ol]复制代码
点击左上角三个点那里,选择新建项目,随便起个名字,我这里是transfer

在“已启用的API 和服务”下,点击+号启用API和服务,然后搜索drive,然后启用Google Drive API。
返回左侧的OAuth 同意屏幕,单击“配置同意屏幕”按钮(靠近右侧面板的右上角),然后选择“外部”并单击“创建”;在下一个屏幕上,输入“应用程序名称”(“rclone”是OK的);输入“用户支持电子邮件”(您自己的电子邮件是可以的);输入“开发人员联系电子邮件”(您自己的电子邮件正常);然后点击“保存”(所有其他数据都是可选的)。
再次单击左侧面板上的“凭据”以返回到“凭据”屏幕。返回左侧的 凭据 ,点击凭据,然后创建凭据,选择“OAuth 客户端 ID”。
选择“桌面应用程序”的应用程序类型,然后单击“创建”。将显示客户端 ID 和客户端密码。记下来。
转到“Oauth同意屏幕”,然后按“发布应用程序”
二、安装rclone
一键安装(https://rclone.org/downloads/)
[ol]sudo -v ; curl https://rclone.org/install.sh | sudo bash[/ol]复制代码
完成之后,我们输入下面命令进行配置
[ol]rclone config[/ol]复制代码
[ol]No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n  #选择n,新建目录
Enter name for new remote.
name> gdrive  #随意的名称,回车后出现下列选项,选Google Drive对应的序号
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, IONOS Cloud, Lyve Cloud, Minio, Netease, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS, Qiniu 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 / In memory object storage system.
   \ (memory)
24 / Internet Archive
   \ (internetarchive)
25 / Jottacloud
   \ (jottacloud)
26 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
27 / Local Disk
   \ (local)
28 / Mail.ru Cloud
   \ (mailru)
29 / Mega
   \ (mega)
30 / Microsoft Azure Blob Storage
   \ (azureblob)
31 / Microsoft OneDrive
   \ (onedrive)
32 / OpenDrive
   \ (opendrive)
33 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ (swift)
34 / Oracle Cloud Infrastructure Object Storage
   \ (oracleobjectstorage)
35 / Pcloud
   \ (pcloud)
36 / Put.io
   \ (putio)
37 / QingCloud Object Storage
   \ (qingstor)
38 / SMB / CIFS
   \ (smb)
39 / SSH/SFTP
   \ (sftp)
40 / Sia Decentralized Cloud
   \ (sia)
41 / Storj Decentralized Cloud Storage
   \ (storj)
42 / Sugarsync
   \ (sugarsync)
43 / Transparently chunk/split large files
   \ (chunker)
44 / Union merges the contents of several upstream fs
   \ (union)
45 / Uptobox
   \ (uptobox)
46 / WebDAV
   \ (webdav)
47 / Yandex Disk
   \ (yandex)
48 / Zoho
   \ (zoho)
49 / premiumize.me
   \ (premiumizeme)
50 / seafile
   \ (seafile)
Storage> 18  #我们这里选18 是google drive,序号会变动
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> #填写你申请OAuth client ID的client_id
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret> #填写你申请OAuth client ID的client_secret
Option scope.
Scope 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 #我们选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 #选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,y是官方获取,n是自己windows cmd.exe relone获取
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "drive" "eyJjbGllbnRfaffiOiI3NzA5OTIwNzAyNDItczFqMGMzMGdiOGJyNDQ0bjAyMmo0cmNnaTFnb2FyaTUuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJjbGllbnRfc2VjcmV0IjoiR09DU1BYLXBjSzZnUGt1UDF5cEYtNlYtemdPYmduaG1HWkciLCJzY29wZSI6ImRyaXZlIn0"
Then paste the result.
Enter a value.
config_token>  #填写windows cmd获取的{}的内容(包括大括号)[/ol]复制代码
到这了,没出现网址,那我们直接把用windows cmd.exe获取,授权过的token复制过来就是大括号{}的内容(包括大括号),然后点击回车
windows获取token
这里我准备好了rclone windows版,地址https://rclone.org/downloads/
下载完后,解压rclone windows版,到d:\rclone
把下面这段复制到cmd里回车
[ol]rclone authorize "drive" "eyJjbGllbnRfaffiOiI3NzA5OTIwNzAyNDItczFqMGMzMGdiOGJyNDQ0bjAyMmo0cmNnaTFnb2FyaTUuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJjbGllbnRfc2VjcmV0IjoiR09DU1BYLXBjSzZnUGt1UDF5cEYtNlYtemdPYmduaG1HWkciLCJzY29wZSI6ImRyaXZlIn0" //修改为你的代码[/ol]复制代码
就会弹到浏览器去验证你得谷歌号,看到如下的界面,“此应用未经google验证”,不用去管,直接点继续
最后生成token code填到我们配置的config_token,如果这里电脑端的cmd一直卡在Waiting for code… Got
code就不动了的话,然后最后报错个超时,不生成token code,就看下面的这一篇有解决方法
解决Rclone生成不了token code的问题
写这一篇又是费了很多脑细胞,配置Rclone的配置环节又出了问题,新版的和老版本的还不一样,没法URL直接到 浏览器来然后返回个verification_code,这就引来了下文如果让Rclone可以正常的生成token code方法。
默认情况下,使用rclone的windows版本来生成那绝对生成不出来,报错信息
[ol]Error: failed to get token: Post "https://oauth2.googleapis.com/token": dial tcp 172.217.163.42:443: i/o timeout[/ol]复制代码
具体可以看下图

即使开着v2ray也是无济于事,cmd没走代理。这里我v2ray的端口是2333,如果和我一样,那就复制了往里敲
[ol]# 使用sock5代理
set http_proxy=socks5://127.0.0.1:2333
set https_proxy=socks5://127.0.0.1:2333[/ol]复制代码
配置完之后,我们再跑一边就显示出来了
取消sock5代理
[ol]set http_proxy=
set https_proxy=[/ol]复制代码

代码, 凭据, 面板

全球vps
OP
  
我们继续
授权过的token复制过来就是大括号{}的内容(包括大括号)填入
[ol]Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "drive" "eyJjbGllbnRfaffiOiI3NzA5OTIwNzAyNDItczFqMGMzMGdiOGJyNDQ0bjAyMmo0cmNnaTFnb2FyaTUuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJjbGllbnRfc2VjcmV0IjoiR09DU1BYLXBjSzZnUGt1UDF5cEYtNlYtemdPYmduaG1HWkciLCJzY29wZSI6ImRyaXZlIn0"
Then paste the result.
Enter a value.
config_token> #填入你获取的token大括号{}的内容(包括大括号)
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> n  #询问是不是团队的云盘,y是团队盘,这里我选择N个人盘
Configuration complete.
Options:
- type: drive
- client_id: 1019418419814-b2bmdpl8ph65ck6ai4inmd62mkak5gmg.apps.googleusercontent.com
- client_secret: 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
- scope: drive
- token: {"access_token":"ya29.a0AfB_byANR77dHgsFkk6u9siqUkaziKV8BukfzN7CABKoMMryTK_3_M0wiNDxLIp6l2Im_Ljd4SUZ3pkaYmqZXGrHnFC2pM7Syr0uFiCovtTXq-rEN5pUHkWedC0msg8c6TvO_y1lq4I8Q6tpbgV_CSu8WUqvGZuvQLqoaCgYKASUSARMSFQHGX2Mi9fRjb95YT1DNnw_S_NdrUA0171","token_type":"Bearer","refresh_token":"1//06_7Qb2Uhmz90CgYIARAAGAYSNwF-L9IrDVhcQ3NbmRjucaHZ-KAAoYymnRPSlKavmaJlxY**pHFxGWvCbcJ0o5v9WZx07UjRtk","expiry":"2023-11-09T01:38:48.2565732+08:00"}
- team_drive:
Keep this "gdrive" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> #回车
Current remotes:
Name                 Type
====                 ====
gdrive               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退出[/ol]复制代码
三、挂载 Google Drive
首先新建一个文件夹用于挂载:
[ol]mkdir /home/gd[/ol]复制代码
开始挂载:
[ol]rclone mount gdrive: /home/gd --allow-other --allow-non-empty --vfs-cache-mode writes --daemon[/ol]复制代码
其中 gdrive 是 rclone 配置时输入的配置名称,/home/gd 是挂载目录,–daemon 是指后台运行。
此时可能会报错:
[ol]Fatal error: mount not ready[/ol]复制代码
这是现在版本的报错不太完善,需要去掉 –daemon 才能看到报错
[ol]rclone mount gdrive: /home/gd --allow-other --allow-non-empty --vfs-cache-mode writes[/ol]复制代码
[ol]一般是因为缺少依赖导致的,我们选择安装
debian 系使用(https://command-not-found.com/fusermount3 获取最新安装代码,包括其他系统):[/ol]复制代码
[ol]apt-get install fuse3[/ol]复制代码[ol]再次执行挂载命令,如果没有报错,就是挂载成功了。
检查挂载:[/ol]复制代码
[ol]df -h[/ol]复制代码
接下来进入 /home/gd 进行一些简单的测试
[ol]cd /home/gd
ls
mkdir test
rm -rf test[/ol]复制代码
如果能够顺利执行,则说明挂载没有问题。
四、amh面板网站备份,定时自动同步到gd网盘
amh面板后台无法执行其他命令(吐槽一下,真不方便),我们只能ssh操作了,ssh连接vps输入
[ol]crontab -e[/ol]复制代码
增加一下命令(每周自动同步备份到gd一次,crontab时间设置,直接amh后台设置后借鉴一下即可,amh后台的任务计划设置都是保存在crontab里面的)
[ol]0 0 * * 1 rclone sync /home/backup /home/gd/amh[/ol]复制代码
保存退出。
进入amh面板后台“任务计划”,我们可以看到刚才的命令已经成功添加并显示

点击立即执行测试,显示任务命令成功,查看gd网盘也已正常同步。此条命令的修改和删除只能在ssh进行,amh后台是无法操作编辑和删除的,以后自己在amh面板创建个自动备份任务,他会自动备份到/home/backup,每周会自动同步到/home/gd/amh,需要注意的是,二个文件夹内容会保持一致,不管那边删除一个文件,另一边也会同步删除
到此教程结束。
借鉴来源:
[ol]https://ivpsr.com/2561.html
https://ivpsr.com/2562.html
https://**updown.com/1065.html
https://pickstar.today/2022/05/vps%E4%BD%BF%E7%94%A8rclone%E6%8C%82%E8%BD%BDgoogle-drive%E8%AF%A6%E7%BB%86%E8%AE%B0%E5%BD%95/[/ol]复制代码
Yzindex   
文章不错,不过我选择备份到S3。
您需要登录后才可以回帖 登录 | 立即注册

返回顶部