找回密码
 立即注册
查看: 317|回复: 1

[分享] AMH面板实现网站备份同步到google drive

[复制链接]

1

主题

2

回帖

27

积分

新手上路

积分
27
芳芳 发表于 2023-11-11 16:12:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖首发于hostloc,转载请注明出处。

512内存vps安装amh面板,速度起飞,比起宝塔面板现在的臃肿,好的不是一点二点,amh面板实际操作下来,并不难用,但他给人的第一印象是很难入手,你说这是为什么呢?我想是大家习惯了使用宝塔吧,不多废话,直接进入主题。

优点:vps上挂载gd,不占用vps空间

最终实现:因为amh面板网站备份后只能ftp、ssh上传到其他vps备份,也没有这方面插件,此方法,挂载gd后,可以当做vps的本地盘,amh面板操作直接备份到gd云盘,当然你也可以做其他用途

系统:debian12

期间有很多坑,自己一步一步填完了,不适合跳着看

一、获取google drive客户端ID和密钥

打开网址:



  1. https://console.developers.google.com/
复制代码
点击左上角三个点那里,选择新建项目,随便起个名字,我这里是transfer



在“已启用的API 和服务”下,点击+号启用API和服务,然后搜索drive,然后启用Google Drive API。

返回左侧的OAuth 同意屏幕,单击“配置同意屏幕”按钮(靠近右侧面板的右上角),然后选择“外部”并单击“创建”;在下一个屏幕上,输入“应用程序名称”(“rclone”是OK的);输入“用户支持电子邮件”(您自己的电子邮件是可以的);输入“开发人员联系电子邮件”(您自己的电子邮件正常);然后点击“保存”(所有其他数据都是可选的)。

再次单击左侧面板上的“凭据”以返回到“凭据”屏幕。返回左侧的 凭据 ,点击凭据,然后创建凭据,选择“OAuth 客户端 ID”。

选择“桌面应用程序”的应用程序类型,然后单击“创建”。将显示客户端 ID 和客户端密码。记下来。

转到“Oauth同意屏幕”,然后按“发布应用程序”

二、安装rclone

一键安装(https://rclone.org/downloads/

  1. sudo -v ; curl https://rclone.org/install.sh | sudo bash
复制代码
完成之后,我们输入下面命令进行配置

  1. rclone config
复制代码
  1. No remotes found, make a new one?
  2. n) New remote
  3. s) Set configuration password
  4. q) Quit config
  5. n/s/q> n  #选择n,新建目录
  6. Enter name for new remote.
  7. name> gdrive  #随意的名称,回车后出现下列选项,选Google Drive对应的序号
  8. Option Storage.
  9. Type of storage to configure.
  10. Choose a number from below, or type in your own value.
  11. 1 / 1Fichier
  12.    \ (fichier)
  13. 2 / Akamai NetStorage
  14.    \ (netstorage)
  15. 3 / Alias for an existing remote
  16.    \ (alias)
  17. 4 / Amazon Drive
  18.    \ (amazon cloud drive)
  19. 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
  20.    \ (s3)
  21. 6 / Backblaze B2
  22.    \ (b2)
  23. 7 / Better checksums for other remotes
  24.    \ (hasher)
  25. 8 / Box
  26.    \ (box)
  27. 9 / Cache a remote
  28.    \ (cache)
  29. 10 / Citrix Sharefile
  30.    \ (sharefile)
  31. 11 / Combine several remotes into one
  32.    \ (combine)
  33. 12 / Compress a remote
  34.    \ (compress)
  35. 13 / Dropbox
  36.    \ (dropbox)
  37. 14 / Encrypt/Decrypt a remote
  38.    \ (crypt)
  39. 15 / Enterprise File Fabric
  40.    \ (filefabric)
  41. 16 / FTP
  42.    \ (ftp)
  43. 17 / Google Cloud Storage (this is not Google Drive)
  44.    \ (google cloud storage)
  45. 18 / Google Drive
  46.    \ (drive)
  47. 19 / Google Photos
  48.    \ (google photos)
  49. 20 / HTTP
  50.    \ (http)
  51. 21 / Hadoop distributed file system
  52.    \ (hdfs)
  53. 22 / HiDrive
  54.    \ (hidrive)
  55. 23 / In memory object storage system.
  56.    \ (memory)
  57. 24 / Internet Archive
  58.    \ (internetarchive)
  59. 25 / Jottacloud
  60.    \ (jottacloud)
  61. 26 / Koofr, Digi Storage and other Koofr-compatible storage providers
  62.    \ (koofr)
  63. 27 / Local Disk
  64.    \ (local)
  65. 28 / Mail.ru Cloud
  66.    \ (mailru)
  67. 29 / Mega
  68.    \ (mega)
  69. 30 / Microsoft Azure Blob Storage
  70.    \ (azureblob)
  71. 31 / Microsoft OneDrive
  72.    \ (onedrive)
  73. 32 / OpenDrive
  74.    \ (opendrive)
  75. 33 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
  76.    \ (swift)
  77. 34 / Oracle Cloud Infrastructure Object Storage
  78.    \ (oracleobjectstorage)
  79. 35 / Pcloud
  80.    \ (pcloud)
  81. 36 / Put.io
  82.    \ (putio)
  83. 37 / QingCloud Object Storage
  84.    \ (qingstor)
  85. 38 / SMB / CIFS
  86.    \ (smb)
  87. 39 / SSH/SFTP
  88.    \ (sftp)
  89. 40 / Sia Decentralized Cloud
  90.    \ (sia)
  91. 41 / Storj Decentralized Cloud Storage
  92.    \ (storj)
  93. 42 / Sugarsync
  94.    \ (sugarsync)
  95. 43 / Transparently chunk/split large files
  96.    \ (chunker)
  97. 44 / Union merges the contents of several upstream fs
  98.    \ (union)
  99. 45 / Uptobox
  100.    \ (uptobox)
  101. 46 / WebDAV
  102.    \ (webdav)
  103. 47 / Yandex Disk
  104.    \ (yandex)
  105. 48 / Zoho
  106.    \ (zoho)
  107. 49 / premiumize.me
  108.    \ (premiumizeme)
  109. 50 / seafile
  110.    \ (seafile)
  111. Storage> 18  #我们这里选18 是google drive,序号会变动
  112. Option client_id.
  113. Google Application Client Id
  114. Setting your own is recommended.
  115. See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
  116. If you leave this blank, it will use an internal key which is low performance.
  117. Enter a value. Press Enter to leave empty.
  118. client_id> #填写你申请OAuth client ID的client_id

  119. Option client_secret.
  120. OAuth Client Secret.
  121. Leave blank normally.
  122. Enter a value. Press Enter to leave empty.
  123. client_secret> #填写你申请OAuth client ID的client_secret
  124. Option scope.
  125. Scope that rclone should use when requesting access from drive.
  126. Choose a number from below, or type in your own value.
  127. Press Enter to leave empty.
  128. 1 / Full access all files, excluding Application Data Folder.
  129.    \ (drive)
  130. 2 / Read-only access to file metadata and file contents.
  131.    \ (drive.readonly)
  132.    / Access to files created by rclone only.
  133. 3 | These are visible in the drive website.
  134.    | File authorization is revoked when the user deauthorizes the app.
  135.    \ (drive.file)
  136.    / Allows read and write access to the Application Data folder.
  137. 4 | This is not visible in the drive website.
  138.    \ (drive.appfolder)
  139.    / Allows read-only access to file metadata but
  140. 5 | does not allow any access to read or download file content.
  141.    \ (drive.metadata.readonly)
  142. scope> 1 #我们选1,赋予权限
  143. Option service_account_file.
  144. Service Account Credentials JSON file path.
  145. Leave blank normally.
  146. Needed only if you want use SA instead of interactive login.
  147. Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
  148. Enter a value. Press Enter to leave empty.
  149. service_account_file>
  150. Edit advanced config?
  151. y) Yes
  152. n) No (default)
  153. y/n> n #选n
  154. Use auto config?
  155. * Say Y if not sure
  156. * Say N if you are working on a remote or headless machine

  157. y) Yes (default)
  158. n) No
  159. y/n> n #选n,y是官方获取,n是自己windows cmd.exe relone获取

  160. Option config_token.
  161. For this to work, you will need rclone available on a machine that has
  162. a web browser available.
  163. For more help and alternate methods see: https://rclone.org/remote_setup/
  164. Execute the following on the machine with the web browser (same rclone
  165. version recommended):
  166.         rclone authorize "drive" "eyJjbGllbnRfaffiOiI3NzA5OTIwNzAyNDItczFqMGMzMGdiOGJyNDQ0bjAyMmo0cmNnaTFnb2FyaTUuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJjbGllbnRfc2VjcmV0IjoiR09DU1BYLXBjSzZnUGt1UDF5cEYtNlYtemdPYmduaG1HWkciLCJzY29wZSI6ImRyaXZlIn0"
  167. Then paste the result.
  168. Enter a value.
  169. config_token>  #填写windows cmd获取的{}的内容(包括大括号)
复制代码
到这了,没出现网址,那我们直接把用windows cmd.exe获取,授权过的token复制过来就是大括号{}的内容(包括大括号),然后点击回车

windows获取token

这里我准备好了rclone windows版,地址https://rclone.org/downloads/

下载完后,解压rclone windows版,到d:\rclone

把下面这段复制到cmd里回车

  1. rclone authorize "drive" "eyJjbGllbnRfaffiOiI3NzA5OTIwNzAyNDItczFqMGMzMGdiOGJyNDQ0bjAyMmo0cmNnaTFnb2FyaTUuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJjbGllbnRfc2VjcmV0IjoiR09DU1BYLXBjSzZnUGt1UDF5cEYtNlYtemdPYmduaG1HWkciLCJzY29wZSI6ImRyaXZlIn0" //修改为你的代码
复制代码
就会弹到浏览器去验证你得谷歌号,看到如下的界面,“此应用未经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版本来生成那绝对生成不出来,报错信息

  1. Error: failed to get token: Post "https://oauth2.googleapis.com/token": dial tcp 172.217.163.42:443: i/o timeout
复制代码
具体可以看下图


即使开着v2ray也是无济于事,cmd没走代理。这里我v2ray的端口是2333,如果和我一样,那就复制了往里敲

  1. # 使用sock5代理
  2. set http_proxy=socks5://127.0.0.1:2333
  3. set https_proxy=socks5://127.0.0.1:2333
复制代码

配置完之后,我们再跑一边就显示出来了

取消sock5代理

  1. set http_proxy=
  2. set https_proxy=
复制代码


1

主题

2

回帖

27

积分

新手上路

积分
27
 楼主| 芳芳 发表于 2023-11-11 16:15:10 | 显示全部楼层
我们继续

授权过的token复制过来就是大括号{}的内容(包括大括号)填入

  1. Option config_token.
  2. For this to work, you will need rclone available on a machine that has
  3. a web browser available.
  4. For more help and alternate methods see: https://rclone.org/remote_setup/
  5. Execute the following on the machine with the web browser (same rclone
  6. version recommended):
  7.         rclone authorize "drive" "eyJjbGllbnRfaffiOiI3NzA5OTIwNzAyNDItczFqMGMzMGdiOGJyNDQ0bjAyMmo0cmNnaTFnb2FyaTUuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJjbGllbnRfc2VjcmV0IjoiR09DU1BYLXBjSzZnUGt1UDF5cEYtNlYtemdPYmduaG1HWkciLCJzY29wZSI6ImRyaXZlIn0"
  8. Then paste the result.
  9. Enter a value.
  10. config_token> #填入你获取的token大括号{}的内容(包括大括号)
  11. Configure this as a Shared Drive (Team Drive)?

  12. y) Yes
  13. n) No (default)
  14. y/n> n  #询问是不是团队的云盘,y是团队盘,这里我选择N个人盘
  15. Configuration complete.
  16. Options:
  17. - type: drive
  18. - client_id: 1019418419814-b2bmdpl8ph65ck6ai4inmd62mkak5gmg.apps.googleusercontent.com
  19. - client_secret: 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
  20. - scope: drive
  21. - 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"}
  22. - team_drive:
  23. Keep this "gdrive" remote?
  24. y) Yes this is OK (default)
  25. e) Edit this remote
  26. d) Delete this remote
  27. y/e/d> #回车

  28. Current remotes:

  29. Name                 Type
  30. ====                 ====
  31. gdrive               drive

  32. e) Edit existing remote
  33. n) New remote
  34. d) Delete remote
  35. r) Rename remote
  36. c) Copy remote
  37. s) Set configuration password
  38. q) Quit config
  39. e/n/d/r/c/s/q> q  #选q退出
复制代码
三、挂载 Google Drive

首先新建一个文件夹用于挂载:

  1. mkdir /home/gd
复制代码
开始挂载:

  1. rclone mount gdrive: /home/gd --allow-other --allow-non-empty --vfs-cache-mode writes --daemon
复制代码
其中 gdrive 是 rclone 配置时输入的配置名称,/home/gd 是挂载目录,–daemon 是指后台运行。

此时可能会报错:

  1. Fatal error: mount not ready
复制代码
这是现在版本的报错不太完善,需要去掉 –daemon 才能看到报错

  1. rclone mount gdrive: /home/gd --allow-other --allow-non-empty --vfs-cache-mode writes
复制代码


一般是因为缺少依赖导致的,我们选择安装

debian 系使用(https://command-not-found.com/fusermount3 获取最新安装代码,包括其他系统):

  1. apt-get install fuse3
复制代码
再次执行挂载命令,如果没有报错,就是挂载成功了。

检查挂载:

  1. df -h
复制代码


接下来进入 /home/gd 进行一些简单的测试

  1. cd /home/gd
  2. ls
  3. mkdir test
  4. rm -rf test
复制代码
如果能够顺利执行,则说明挂载没有问题。

四、amh面板网站备份,定时自动同步到gd网盘

amh面板后台无法执行其他命令(吐槽一下,真不方便),我们只能ssh操作了,ssh连接vps输入

  1. crontab -e
复制代码
增加一下命令(每周自动同步备份到gd一次,crontab时间设置,直接amh后台设置后借鉴一下即可,amh后台的任务计划设置都是保存在crontab里面的)

  1. 0 0 * * 1 rclone sync /home/backup /home/gd/amh
复制代码


保存退出。

进入amh面板后台“任务计划”,我们可以看到刚才的命令已经成功添加并显示



点击立即执行测试,显示任务命令成功,查看gd网盘也已正常同步。此条命令的修改和删除只能在ssh进行,amh后台是无法操作编辑和删除的,以后自己在amh面板创建个自动备份任务,他会自动备份到/home/backup,每周会自动同步到/home/gd/amh,需要注意的是,二个文件夹内容会保持一致,不管那边删除一个文件,另一边也会同步删除

到此教程结束。



借鉴来源:
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/

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|IDCeve

GMT+8, 2024-5-20 11:36 , Processed in 0.052061 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表