数据是现代生活的基石,保护它们免受意外丢失至关重要。本教程将为您提供一步一步的指导,帮助您使用 Rclone 将 VPS 数据备份到 OneDrive,即使您没有太多的技术背景。
什么是 Rclone? Rclone 是一个开源的命令行工具,它允许您同步文件和目录到多种云存储服务,如 OneDrive、Google Drive 和 Amazon S3。它被设计得非常灵活,支持多种操作系统,包括 Windows、macOS 和 Linux。
Github项目地址:https://github.com/rclone/rclone
第一步:安装 Rclone
-
访问 Rclone 的官方网站(rclone.org)并下载适合您操作系统的版本。
-
对于 Linux 用户,您可以使用包管理器安装 Rclone。例如,在 Ubuntu 上,您可以使用以下命令:
curl https://rclone.org/install.sh | sudo bash
第二步:获取OneDrive授权码
-
在Rclone下载页面下载与自己电脑系统对应的程序,并解压。
-
在解压目录里打开终端,并运行
rclone.exe
程序。PS D:\Softwares\Rclone\rclone-v1.65.2-windows-amd64> ./rclone authorize "onedrive"
-
当操作成功后,系统会自动弹出浏览器,进入 OneDrive 登录界面。在完成授权后,您将在终端窗口中看到授权码的出现。请将这个授权码复制下来备用,注意确保包含大括号。
{"access_token":"eyJ0eXAiOiJKV1QiLCJub25jZSI6IjN6LWVXQ3JZOVpNc092YVBRTjZiaTFacVR3NDV1UzZZc3NGSFRiUi1rc3ciLCJhbGciOiJSUzI1NiIsIng1dCI6IlhSdmtvOFA3QTNVYVdTblU3Yk05blQwTWpoQSIsImtpZCI6IlhSdmtvOFA3QTNVYVdTblU3Yk05blQwTWpoQSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC81ZGYwMjg0Ny01ZTNkLTRhYWEtYWVkNy1hMDdkMDFiNWFkMjYvIiwiaWF0IjoxNzA5NTU2ODYwLCJuYmYiOjE3MDk1NTY4NjAsImV4cCI6MTcwOTU2MTc1MiwiYWNjdCI6MCwiYWNyIjoiMSIsImFpbyI6IkFWUUFxLzhXQUFBQStGcEI1aWJmb2ZibjFKOEovZ2RMZTh0eU9LbWNDdlZJTTRVeTN0cWd4bDR0YkJvWU1rRFJHNGZ5aG1GTlZkYXMxL0Z1SExKRHBkN29MYk1qcnZ6V0NZV1ZxaEsxTlE4MENxNzNoWDZVWFRRPSIsImFtciI6WyJwd2QiLCJtZmEiXSwiYXBwX2Rpc3BsYXluYW1lIjoicmNsb25lIiwiYXBwaWQiOiJiMTU2NjVkOS1lZGE2LTQwOTItODUzOS0wZWVjMzc2YWZkNTkiLCJhcHBpZGFjciI6IjEiLCJmYW1pbHlfbmFtZSI6IuWImCIsImdpdmVuX25hbWUiOiLmrKMiLCJpZHR5cCI6InVzZXIiLCJpcGFkZHIiOiI1MS4xNTkuMTAzLjE0MSIsIm5hbWUiOiLliJgg5qyjIiwib2lkIjoiNWI2YzAzMDEtYWI5Zi00MTA2LThhYzEtMjVkMGJkYjNiYWFkIiwicGxhdGYiOiIzIiwicHVpZCI6IjEwMDMyMDAxQTg4REUxRDMiLCJyaCI6IjAuQVZVQVJ5andYVDFlcWtxdTE2QjlBYld0SmdNQUFBQUFBQUFBd0FBQUFBQUFBQUNJQUxrLiIsInNjcCI6IkZpbGVzLlJlYWQgRmlsZX......vcOb7m2x1jWMe_zhqKo2ixXV89AzAQ8alrzI1ZLpVG2Oh914TgK4JuIfB8H_4DZSSa1X6YGjsqBRzgMrSD_0pOgNERjQ2Fxf2jtT_89SyIpk_TW_u7EmFaunr_BNDeJarTEKx3qBejrrEZvBA","expiry":"2024-03-04T22:15:51.4178223+08:00"}
第三步:配置 Rclone
-
运行
rclone config
命令开始配置过程。rclone config
-
由于刚安装还没有配置,在以下弹出的消息后选择
n
,创建一个新控制器。No remotes found, make a new one? n) New remote s) Set configuration password q) Quit config n/s/q> n
-
输入新遥控器的名称。
Enter name for new remote. name> data_backup
-
按照屏幕上的指示操作,选择 OneDrive,这里我选择
34
。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, ArvanCloud, Ceph, ChinaMobile, Cloudflare, DigitalOcean, Dreamhost, GCS, HuaweiOBS, IBMCOS, IDrive, IONOS, LyveCloud, Leviia, Liara, Linode, Minio, Netease, Petabox, RackCorp, Rclone, Scaleway, SeaweedFS, StackPath, Storj, Synology, TencentCOS, Wasabi, Qiniu and others \ (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 / ImageKit.io \ (imagekit) 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 / Linkbox \ (linkbox) 29 / Local Disk \ (local) 30 / Mail.ru Cloud \ (mailru) 31 / Mega \ (mega) 32 / Microsoft Azure Blob Storage \ (azureblob) 33 / Microsoft Azure Files \ (azurefiles) 34 / Microsoft OneDrive \ (onedrive) 35 / OpenDrive \ (opendrive) 36 / OpenStack Swift (Rackspace Cloud Files, Blomp Cloud Storage, Memset Memstore, OVH) \ (swift) 37 / Oracle Cloud Infrastructure Object Storage \ (oracleobjectstorage) 38 / Pcloud \ (pcloud) 39 / PikPak \ (pikpak) 40 / Proton Drive \ (protondrive) 41 / Put.io \ (putio) 42 / QingCloud Object Storage \ (qingstor) 43 / Quatrix by Maytech \ (quatrix) 44 / SMB / CIFS \ (smb) 45 / SSH/SFTP \ (sftp) 46 / Sia Decentralized Cloud \ (sia) 47 / Storj Decentralized Cloud Storage \ (storj) 48 / Sugarsync \ (sugarsync) 49 / Transparently chunk/split large files \ (chunker) 50 / Union merges the contents of several upstream fs \ (union) 51 / Uptobox \ (uptobox) 52 / WebDAV \ (webdav) 53 / Yandex Disk \ (yandex) 54 / Zoho \ (zoho) 55 / premiumize.me \ (premiumizeme) 56 / seafile \ (seafile) Storage> 34
-
不需要填写
client_id
,直接回车
。Option client_id. OAuth Client Id. Leave blank normally. Enter a value. Press Enter to leave empty. client_id>
-
不需要填写
client_secret
,直接回车
。Option client_secret. OAuth Client Secret. Leave blank normally. Enter a value. Press Enter to leave empty. client_secret>
-
当选择 OneDrive 服务器区域时,如果您使用的是 国际版,请输入
1
;如果您使用的是 世纪互联,请键入4
。Option region. Choose national cloud region for OneDrive. Choose a number from below, or type in your own string value. Press Enter for the default (global). 1 / Microsoft Cloud Global \ (global) 2 / Microsoft Cloud for US Government \ (us) 3 / Microsoft Cloud Germany \ (de) 4 / Azure and Office 365 operated by Vnet Group in China \ (cn) region> 1
-
编辑高级配置,选择
n
。Edit advanced config? y) Yes n) No (default) y/n> n
-
使用 Web 浏览器自动通过远程验证 rclone?
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
-
输入授权码。
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 "onedrive" Then paste the result. Enter a value. config_token> {"access_token":"eyJ0eXAiOiJKV1QiLCJub25jZSI6IjN6LWVXQ3JZOVpNc092YVBRTjZiaTFacVR3NDV1UzZZc3NGSFRiUi1rc3ciLCJhbGciOiJSUzI1NiIsIng1dCI6IlhSdmtvOFA3QTNVYVdTblU3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GjsqBRzgMrSD_0pOgNERjQ2Fxf2jtT_89SyIpk_TW_u7EmFaunr_BNDeJarTEKx3qBejrrEZvBA","expiry":"2024-03-04T22:15:51.4178223+08:00"}
-
选择类型,直接
回车
。Option config_type. Type of connection Choose a number from below, or type in an existing string value. Press Enter for the default (onedrive). 1 / OneDrive Personal or Business \ (onedrive) 2 / Root Sharepoint site \ (sharepoint) / Sharepoint site name or URL 3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite \ (url) 4 / Search for a Sharepoint site \ (search) 5 / Type in driveID (advanced) \ (driveid) 6 / Type in SiteID (advanced) \ (siteid) / Sharepoint server-relative path (advanced) 7 | E.g. /teams/hr \ (path) config_type>
-
选择驱动器,直接点
回车
。Option config_driveid. Select drive you want to use Choose a number from below, or type in your own string value. Press Enter for the default (b!xEAI2_dCyUync9xFU_kZYbecajS-6qVHn00tWyY_iZ1sAnm5TukaSK4LEtrA7lWp). 1 / OneDrive (business) \ (b!xEAI2_dCyUync9xFU_******-******_iZ1sAnm5TukaSK4LEtrA7lWp) config_driveid>
-
输入
y
继续Found drive "root" of type "business" URL: https://name-my.sharepoint.com/personal/name_onmicrosoft_com/Documents y) Yes (default) n) No y/n> y
-
看到提示
Configuration complete.
说明配置文件就全部设置完成了,最后会让我们选择是否保留配置文件,输入y
选择默认就可以了。Keep this "data_backup" remote? y) Yes this is OK (default) e) Edit this remote d) Delete this remote y/e/d> y
-
这里会显示你配置文件,选择
q
退出。Name Type ==== ==== data_backup 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备份脚本
-
确定您想要备份的文件和目录。
-
创建脚本
nano backup.sh
-
复制粘贴以下命令,
Ctrl+x
再输入y
保存并退出。rclone sync /root/data_backup data_backup:backup/data_backup
/root/data_backup
是要备份的文件或者文件夹,data_backup
是你设置的配置文件,backup/data_backup
是你OneDrive网盘的备份路径。 -
为创建的脚本赋予执行权限
chmod +x backup.sh
此时,执行 ./backup.sh
就可以执行备份任务了。
第四步:自动备份
-
使用
cron
来设置定时任务,自动执行备份。这是一个在 Linux 系统中用于定时执行任务的程序。 -
编辑您的 crontab 文件:
crontab -e
-
添加以下行来每天凌晨 7 点执行备份:
0 7 * * * /root/backup.sh
附加资源
- Rclone 官方文档:提供了完整的命令和选项列表,以及如何使用它们的说明。
- 社区论坛:如果您在设置过程中遇到问题,可以寻求社区的帮助。
总结
通过本教程,您应该能够理解 Rclone 的基本概念,并能够将您的 VPS 数据备份到 OneDrive。记住,定期备份是保护您的数据不受损失的最佳实践。
评论区